下载mysql
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.36-1.el7.x86_64.rpm-bundle.tar
解压安装
tar xvf mysql-8.0.36-1.el7.x86_64.rpm-bundle.tar
yum -y localinstall *.rpm
初始化
mysqld --initialize --user=mysql
需要选择mysql用户,否则可能报错
如果异常,删除这里面的所有文件然后重新初始化
cd /var/lib/mysqltm -rf *
mysqld --initialize --user=mysql
修改密码:
mysql -u root -p
密码
cat /var/log/mysqld.logALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;或者一部到位
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';use mysql;
update user set host='%' where user='root';
flush privileges;
docker 安装mysql
mdkir /data/mysql/logsmkdir /data/mysql/logsmkdir /data/mysql/confdocker run --restart=always --name mysql --privileged=true -d -p 13306:3306 -v /data/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /data/mysql/logs:/logs -v /data/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.29
my.cnf 配置
[client]
default-character-set = utf8mb4[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL# Custom config should go here
# 字符集
character_set_server=utf8mb4
collation-server=utf8mb4_unicode_ci
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB# 是否对sql语句大小写敏感,0:大小写敏感,1:忽略大小写区别。,只能在初始化服务器时配置。禁止在服务器初始化后更改
# 设置为2时,表名和数据库名按声明存储,但以小写形式进行比较
lower_case_table_names = 2# 最大连接数
max_connections = 1000# Innodb缓存池大小
innodb_buffer_pool_size = 4G# 表文件描述符的缓存大小
table_open_cache_instances=1
table_open_cache=2000
table_definition_cache=2000#!includedir /etc/mysql/conf.d/
报错处理 https://blog.csdn.net/lz6363/article/details/117778712
2059 - Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(../Frameworks/caching_sha2_password.so, 2): image not found
原因:由于目前已有的客户端连接软件还不支持mysql 8新增加的加密方式caching_sha2_password,所以我们需要修改用户的加密方式,将其改为老的加密验证方式
使用命令行登录mysql
use mysql;select user,plugin from user where user='root';
+------+-----------------------+
| user | plugin |
+------+-----------------------+
| root | caching_sha2_password |
| root | caching_sha2_password |
+------+-----------------------+
2 rows in set (0.00 sec)
可以看到加密方式为caching_sha2_password
更改需要通过远程连接的用户的加密方式为mysql_native_password即可,这里用root用户举例:
-- 更改用户加密方式
alter user 'root'@'%' identified with mysql_native_password by '123456';-- 刷新配置环境
flush privileges;