一、下载
1)打开https://dev.mysql.com/downloads/mysql/
2)选择 Linux - Generic
3)下载 (mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz)
二、解压
# cd /usr/local/src
# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
# xz -d mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz && tar jxf mysql-8.0.20-linux-glibc2.12-x86_64.tar
三、配置并安装
1) vim /etc/my.cnf # 将下面内容粘贴到里面
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /mysql_data/mysqld_multi.log
[mysqld]
user=mysql
basedir = /usr/local/mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld3306]
datadir=/mysql_data/data3306
port=3306
server_id=3306
socket=/tmp/data3306.sock
log-output=file
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /mysql_data/data3306/slow.log
log-error = /mysql_data/data3306/error.log
binlog_format = mixed
log-bin = /mysql_data/data3306/mysql3306_bin
[mysqld3307]
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/mysql_data/data3307
port=3307
server_id=3307
socket=/tmp/data3307.sock
log-output=file
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /mysql_data/data3307/slow.log
log-error = /mysql_data/data3307/error.log
binlog_format = mixed
log-bin = /mysql_data/data3307/mysql3307_bin
2)初始化数据表
# 准备数据目录
mkdir /mysql_data/{data3306,data3307}
chown -R mysql.mysql /mysql_data
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/mysql_data/data3306 --initialize
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/mysql_data/data3307 --initialize
注意:这期间会产生密码,纪录下来
3)启动数据库
mysqld_multi start 3306
mysqld_multi start 3307
# 确保已经运行
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is running
4)登录
mysql -uroot -S套接字地址 -p"密码"
# 如果希望使用端口号登录
# cd ~
# vim .my.cnf #内容如下
[client]
host=127.0.0.1
5)修改密码
# flush privileges; # 修改密码不成功报错时先执行它
# mysql -S/tmp/data3306.sock -p"密码"
# ALTER USER "root"@"localhost" IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY "新密码";
# flush privileges;
6)停止
# 实例 为 3306 和 3307
mysqld_multi --user=root --password="密码" stop 实例