Linux 安装 MySql5.7

首先在官网下载对应版本的Linux安装包。一般来说应用 community 版本就可以。
mysql community version download addr

1. 将文件上传至 Linux 并解压

# 我将文件放到了HOME文件下
[root@192 home]# tar -zxf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
# 移动到 usr/local 下
[root@192 home]# mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql

2. 创建 mysql 用户和组,并授权 mysql文件夹 读写权限

[root@192 mysql]# groupadd mysql
[root@192 mysql]# useradd -r -g mysql mysql
[root@192 local]# chown -R mysql mysql/
[root@192 local]# chgrp -R mysql mysql/

3. 修改配置文件

[root@192 etc]# vim my.cnf
==========================================
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

# my append
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
character_set_server=utf8mb4
init_connect=‘SET NAMES utf8‘
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
#不区分大小写
#lower_case_table_names = 1
#
#sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#
#max_connections=5000
#
default-time_zone = ‘+8:00
=======================================

4. 初始化数据库

# 检查一下是否安装了这个程序,没有的话安装一下
[root@192 etc]# yum list installed|grep libaio
libaio.x86_64                         0.3.109-13.el7                   @anaconda
# 根据上面配置文件中的 log 文件地址创建 log文件
[root@192 home]# touch /var/log/mariadb/mariadb.log
# 授权 mysql 用户
[root@192 home]# chmod 777 /var/log/mariadb/mariadb.log
[root@192 home]# chown mysql:mysql /var/log/mariadb/mariadb.log
# initlize , 进入mysql/bin 目录下
[root@192 bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
# 这是密码,安装后看自己的。找不到了就去看日志。
2020-05-10T07:05:01.535756Z 1 [Note] A temporary password is generated for root@localhost: htE%6JojCror

5. 启动服务,修改密码

# 根据配置创建 pid-file 文件
[root@192 run]# mkdir mariadb
[root@192 run]# touch mariadb/mariadb.pid
[root@192 run]# sudo chmod 777 mariadb/mariadb.pid
[root@192 run]# chown mysql:mysql mariadb
[root@192 run]# chown mysql:mysql mariadb/mariadb.pid
# 启动服务
[root@192 run]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.. SUCCESS!
[root@192 run]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.28
# 修改密码
mysql> set password=password(‘123456‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> UPDATE `mysql`.`user` SET `Host` = ‘%‘,  `User` = ‘root‘  WHERE (`Host` = ‘localhost‘) AND (`User` = ‘root‘);
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> UPDATE `mysql`.`user` SET `Host`=‘%‘, `User`=‘root‘, `Select_priv`=‘Y‘, `Insert_priv`=‘Y‘, `Update_priv`=‘Y‘, `Delete_priv`=‘Y‘, `Create_priv`=‘Y‘, `Drop_priv`=‘Y‘, `Reload_priv`=‘Y‘, `Shutdown_priv`=‘Y‘, `Process_priv`=‘Y‘, `File_priv`=‘Y‘, `Grant_priv`=‘Y‘, `References_priv`=‘Y‘, `Index_priv`=‘Y‘, `Alter_priv`=‘Y‘, `Show_db_priv`=‘Y‘, `Super_priv`=‘Y‘, `Create_tmp_table_priv`=‘Y‘, `Lock_tables_priv`=‘Y‘, `Execute_priv`=‘Y‘, `Repl_slave_priv`=‘Y‘, `Repl_client_priv`=‘Y‘, `Create_view_priv`=‘Y‘, `Show_view_priv`=‘Y‘, `Create_routine_priv`=‘Y‘, `Alter_routine_priv`=‘Y‘, `Create_user_priv`=‘Y‘, `Event_priv`=‘Y‘, `Trigger_priv`=‘Y‘, `Create_tablespace_priv`=‘Y‘, `ssl_type`=‘‘, `ssl_cipher`=‘‘, `x509_issuer`=‘‘, `x509_subject`=‘‘, `max_questions`=‘0‘, `max_updates`=‘0‘, `max_connections`=‘0‘, `max_user_connections`=‘0‘, `plugin`=‘mysql_native_password‘, `authentication_string`=‘*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9‘, `password_expired`=‘N‘, `password_last_changed`=‘2017-11-20 12:41:07‘, `password_lifetime`=NULL, `account_locked`=‘N‘ WHERE  (`User`=‘root‘);
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

6. 开机自启动、

[root@192 init.d]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@192 init.d]# chkconfig --add mysqld
[root@192 init.d]# vim /etc/profile
# mysql
export PATH=/usr/local/mysql/bin:$PATH
[root@192 init.d]# source /etc/profile
grant all privileges on *.* to ‘新用户名‘@‘%‘ identified by ‘新密码‘;
flush privileges;

Linux 安装 MySql5.7

上一篇:selenium(11)-web UI自动化实战


下一篇:.net core 3.1开发遇到的问题