MySQL8
- 安装mysql
sudo dnf install @mysql
- 开机自启
sudo systemctl enable --now mysqld
- 查看状态
sudo systemctl status mysqld
- root账户密码设置
(/var/log/mysqld.log查看初始密码)
查看mysql初始密码
grep 'temporary password' /var/log/mysqld.log
sudo mysql_secure_installation
- root登录设置可远程连接
mysql -u root -p
use mysql
update user set host = '%' where user = 'root';
flush privileges;
quit
- 重启mysql
sudo systemctl restart mysqld
- 如果远程不可连接,去阿里云ECS设置安全组,开放3306。
- 查看MySQL的配置文件位置
mysqld --verbose --help|grep -A 1 'Default options'
MySQL5.7
- 查看卸载原有的mysql
rpm -qa |grep mysql
逐一卸载:rpm -e mysql-community-server-5.7.30-1.el7.x86_64等等 - 查看有没有wget的,没有则先安装wget
yum install wget
- 下载mysql的rpm
wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
- 安装mysql的rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
这时候会在 /etc/yum.repos.d/目录下生成两个文件
mysql-community.repo和mysql-community-source.repo
修改repo文件(安装5.7,不要8.0)
cd /etc/yum.repos.d/
vim mysql-community.repo
将 [mysql57-community] 下的 enabled 设置为1,表示打开5.7
将 [mysql80-community] 下的 enabled 设置为0,表示关闭8.0
安装mysql
yum -y install mysql-community-server
查看版本
mysql --version
启动并查看状态
systemctl start mysqld.service
systemctl status mysqld.service
问题解决:
1、出现Error: Unable to find a match: mysql-community-server
执行:
yum module disable mysql
yum -y install mysql-community-server
2、出现 Error: GPG check FAILED问题
yum install mysql-community-server --nogpgcheck
或者
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
3、Error: Transaction test error:
file /etc/my.cnf from install of mysql-community-server-5.7.40-1.el7.x86_64 conflicts with file from package mariadb-connector-c-config-3.1.11-2.el8_3.noarch
解决: rpm -qa | grep mariadb
删除xxrpm -ev --nodeps xxxxx
4、
You must reset your password using ALTER USER statement before executing this statement.
修改密码:
ALTER USER USER() IDENTIFIED BY ‘password’;