# 查看mysql是否已安装
rpm -qa|grep mysql
若有可用 rpm -e卸载
# 卸载系统自带mariadb
rpm -qa|grep mariadb
yum remove -y mariadb-xxxxxxxxxxxxxxx
# 安装依赖libaio
libaio是Linux下的一个异步非阻塞接口,它提供了以异步非阻塞方式来读写文件的方式,读写效率比较高。
ps aux | grep libaio
ps -ef | grep libaio
没有的话,就安装:
yum install -y libaio
yum install -y cmake make gcc gcc-c++ libaio ncurses ncurses-devel
# 下载YUM源
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
##
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
# 安装
yum -y install mysql-community-server
通过如下命令查看默认密码
grep "temporary password" /var/log/mysqld.log
# 初始化
mysql_secure_installation
按照要求配置相关信息
# 配置my.cnf
vim /etc/my.cnf
[mysqld]
port=3306
character_set_server=utf8
init_connect='SET NAMES utf8'
#不区分大小写
lower_case_table_names = 1
#不开启sql严格模式
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# FAQ
# 忘记密码怎么办
vi /etc/my.cnf
在[mysqld]的段中加上一句:
skip-grant-tables
然后重启MySQL
systemctl restart mysqld
重新登录,免密不用输
mysql -uroot -p
选择数据库为mysql
use mysql
执行命令
update user set authentication_string=password('你的密码') where user='root';
flush privileges;
然后把/etc/my.cnf里加的skip-grant-tables删掉
重启MySQL
systemctl restart mysqld
# 允许弱口令(按需)
# 查看口令要求
show variables like 'validate_password%';
# 修改口令为弱口令
set global validate_password_policy=LOW;
# 修改密码长度
set global validate_password_length=6;
# 允许远程连接
## 必须先执行这行
update user set host = '%' where user = 'root';
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;