-
创建mysql 8.0工作目录:
mkdir -p /usr/local/dev/mysql-8.0
-
下载mysql 8.0压缩文件:
# https://dev.mysql.com/downloads/mysql/ 可以选择需要下载的mysql版本信息 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
-
解压mysql压缩文件:
tar xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz cd mysql-8.0.20-linux-glibc2.12-x86_64 mv * /usr/local/dev/mysql-8.0/
-
创建mysql数据目录:
mkdir /usr/local/dev/mysql-8.0/data
-
创建用户组:
groupadd mysql # 创建用户组 useradd -g mysql mysql # 创建用户并将其加入mysql用户组
-
授权用户:
chown -R mysql.mysql /usr/local/dev/mysql-8.0
-
初始化mysql 8.0基础信息:
cd /usr/local/dev/mysql-8.0/bin ./mysqld --user=mysql --basedir=/usr/local/dev/mysql-8.0 --datadir=/usr/local/dev/mysql-8.0/data/ --initialize
得到临时密码,如下图:
pe4Y57*OW>:y
就是mysql 8.0登录使用的临时密码。 -
编辑
my.cnf
配置文件,注释mysqld_safe:vi /etc/my.cnf [mysqld] basedir=/usr/local/dev/mysql-8.0 datadir=/usr/local/dev/mysql-8.0/data socket=/tmp/mysql.sock character-set-server=UTF8MB4 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # [mysqld_safe] # log-error=/usr/local/dev/mysal-8.0/logs/mysqld-error.log # pid-file=/tmp/mysqld.pid :wq! # 保存并退出
-
添加mysqld服务到系统:
cd /usr/local/dev/mysql-8.0 cp -a ./support-files/mysql.server /etc/init.d/mysql
-
授权以及添加服务:
chmod +x /etc/init.d/mysql chkconfig --add mysql
-
启动mysql服务:
service mysql start
-
查看mysql服务启动状态:
service mysql status
-
将mysql命令添加到服务:
ln -s /usr/local/dev/mysql-8.0/bin/mysql /usr/bin
-
登录mysql:
mysql -uroot -p # 密码使用之前随机生成的密码
-
修改root密码并生效:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; flush privileges;
-
选择mysql数据库(系统设置库):
use mysql;
-
修改远程连接并生效:
update user set host='%' where user='root'; flush privileges;