CentOS 7下安装MySQL 8
官方镜像:http://dev.mysql.com/downloads/mirrors.html
中科大镜像:http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-8.0/
# rpm -qa | grep -i mysql //检查是否已安装MySQL,grep的-i选项表示匹配时忽略大小写
# rpm -qa | grep -i mariadb
mariadb-libs-5.5.52-1.el7.x86_64
# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps //卸载,–nodeps忽略依赖关系
# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-8.0/mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar
# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar
# yum install -y perl-Module-Install.noarch numactl libaio
# tar -xf mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar
# rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm
# rpm -ivh mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm
# rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm //安装mysql客户端
# rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm //安装mysql服务端
# rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm
若报错:
# rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-devel-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
pkgconfig(openssl) is needed by mysql-community-devel-8.0.18-1.el7.x86_64
解决:
# yum install openssl-devel
# mysql -V
# vim /etc/my.cnf //配置my.cnf
# systemctl start mysqld //启动MySQL服务
# systemctl status mysqld //查看MySQL运行状态
# systemctl restart mysqld //重启MySQL服务
# grep "password" /var/log/mysqld.log //查看默认root用户密码
//设置开机启动
# systemctl enable mysqld
# systemctl daemon-reload
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
port=3306
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character_set_server=utf8 #设置MySQL服务器默认字符集
explicit_defaults_for_timestamp=true
[client]
default_character_set=utf8 #设置MySQL客户端默认字符集
注:MySQL 8.0 之前的版本中加密规则是
mysql_native_password
,而在MySQL 8.0 之后,加密规则默认是caching_sha2_password
。而大部分已经上线的应用程序的MySQL驱动一般不支持caching_sha2_password
,因此需要将 MySQL 8.0 用户登录密码加密规则还原成mysql_native_password
重置root@localhost
初始密码
> alter user 'root'@'localhost' identified with mysql_native_password by 'new password';
> flush privileges;
设置允许root用户远程访问
> create user 'root'@'%' identified with mysql_native_password by 'new password';
> grant all privileges on *.* to 'root'@'%';
> flush privileges;
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/02/12/centos-7-install-mysql-8/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论