前言 都说MySql8.x
比5.7
快两倍,可以参考 一下。 但不支持从 MySQL 8.0
降级到 MySQL 5.7
(或从某个 MySQL 8.0
版本降级到任意一个更早的 MySQL 8.0
版本)。数据备份方式还是可以的。
注意MySql8
的用户安全策略的改变
注意MySql8
编码格式
支撑内网服务器安装
准备 下载 1 2 3 4 5 6 7 8 wget https://cdn.mysql.com//Downloads/MySQL-8.2/mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar tar -xvf mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar wget https://cdn.mysql.com//Downloads/MySQL-8.2/mysql-community-server-8.2.0-1.el7.x86_64.rpm wget https://cdn.mysql.com//Downloads/MySQL-8.2/mysql-community-libs-8.2.0-1.el7.x86_64.rpm wget https://cdn.mysql.com//Downloads/MySQL-8.2/mysql-community-client-8.2.0-1.el7.x86_64.rpm
安装 先查看有没有 mariadb
有就强制卸载 1 rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
强制安装 1 2 3 4 5 6 rpm -ivh mysql-community-common-8.2.0-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-server-8.2.0-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-libs-8.2.0-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-client-8.2.0-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-devel-8.2.0-1.el7.x86_64.rpm --nodeps --force
这时候查看安装 1 2 3 4 rpm -qa|grep mysql mysql-community-server-8.2.0-1.el7.x86_64 mysql-community-client-8.2.0-1.el7.x86_64 mysql-community-libs-8.2.0-1.el7.x86_64
初始化配置
配置路径 /opt/db/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 [mysql] default-character-set =utf8mb4 socket =/opt/db/mysql_data/mysql.sock [mysqld] skip-name-resolve port =3331 datadir =/opt/db/mysql_data socket =/opt/db/mysql_data/mysql.sock log-error =/opt/db/mysql_log/mysqld.log pid-file =/opt/db/mysqld/mysqld.pid max_connections =200 character-set-server =utf8mb4 collation-server =utf8mb4_0900_ai_ci default-storage-engine =INNODB lower_case_table_names =1 max_allowed_packet =16M lc-messages-dir =/usr/share/MySQL-8.2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 rm -rf /opt/db/mysql/rm -rf /opt/db/mysqld/rm -rf /opt/db/mysql_datarm -rf /opt/db/mysql_logmkdir -p /opt/db/mysql/mkdir -p /opt/db/mysqld/mkdir -p /opt/db/mysql_datamkdir -p /opt/db/mysql_logchown mysql:mysql /opt/db/ -Rchmod 777 -R /opt/db/mysqldsudo mysqld --initialize --user=mysql --basedir=/usr setenforce 0 systemctl start mysqld.service systemctl status mysqld.service systemctl enable mysqld cat /opt/db/mysql_log/mysqld.log
报错解决 mysqld: error while loading shared libraries: libaio.so.1
Can't find error-message file '/usr/share/MySQL-8.2/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
1 lc-messages-dir =/usr/share/MySQL-8.2
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
1 2 rm -rf /var/lib/mysql/mysql.socksystemctl restart mysqld
查看安装日志中的密码 1 cat /opt/db/mysql_log/mysqld.log | grep password
登录
比如这个uQ3sw%Cu;IKk
复制粘贴就可以了。
修改密码 1 2 3 4 5 6 7 flush privileges; alter user 'root' @'localhost' identified by "123456" ; create user root@'%' identified by '123456' ; grant all privileges on *.* to root@'%' ; flush privileges;
无密码的方式,可用于找回密码。 输入一百次也输入不对默认密码 配置文件 MySQL 免密码登录 编辑 MySQL 的配置文件
在 [mysqld]
下添加
修改密码(记得删除my.cnf
文件的东西)
1 2 3 4 5 6 7 8 # 这里需要先刷新权限,不然会报错。 flush privileges; alter user 'root'@'localhost' identified by "123456"; # alter user 'root'@'localhost' identified WITH caching_sha2_password by "123456"; #创建远程连接 create user root@'%' identified by '123456'; grant all privileges on *.* to root@'%'; flush privileges;
或者
1 2 3 bin/mysql use mysql; update user SET Password = 'new-password' WHERE User = 'root';
基本配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 [mysql] default-character-set=utf8mb4 socket=/opt/db/mysql_data/mysql.sock [mysqld] skip-name-resolve port = 3331 datadir=/opt/db/mysql_data socket=/opt/db/mysql_data/mysql.sock log-error=/opt/db/mysql_log/mysqld.log pid-file=/opt/db/mysqld/mysqld.pid max_connections=200 character-set-server=utf8mb4 collation-server=utf8mb4_0900_ai_ci default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M lc-messages-dir=/usr/share/MySQL-8.2
推荐
MySQL8.0创建用户及其配置 MySQL8.0新特性-新的索引方式 MySQL8.0新特性-通用表表达式(CTE) MySQL8.0新特性-窗口函数 MySQL8.0新特性-InnoDB增强 MySQL8.0新特性-JSON增强 [官方介绍]([https://dev.mysql.com/doc/refman/8.0/en/create-index.html#create-index-functional-key-parts
本文地址: https://github.com/maxzhao-it/blog/post/26543/