修改/etc/hostname文件,替换原有内容并重启服务器。
查看系统是否由默认安装的MariaDB数据库,如果有,安装下面操作卸载即可,如果没有,可以跳过这一步。
rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
卸载系统安装的MariaDB数据库
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件,
官方地址:MySQL :: Download MySQL Yum Repository
wget https://dev.mysql.com/get/mysql80-community-release-el8-2.noarch.rpm
复制上面链接,使用wget进行下载
wget https://dev.mysql.com/get/mysql80-community-release-el8-2.noarch.rpm
yum install -y mysql80-community-release-el8-2.noarch.rpm
yum repolist all | grep mysql
yum源中默认启用的安装包版本为MySQL 8.0,查看MySQL 8.0 安装的相关依赖
yum repolist enabled | grep mysql.*
MySQL的相关依赖就会列出来,MySQL版本和文件的 下载路径。
查询MySQL的相关依赖,输入下面命令
yum -y install mysql-community-server
备注:
如果报如下错误,禁用CentOS8自带mysql模块
All matches were filtered out by modular filtering for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server
禁用CentOS8自带mysql模块
yum -y module disable mysql
systemctl start mysqld
运行一下命令查看一下运行状态
systemctl status mysqld
第一次安装完没有设置密码,所以只能使用MySQL安装时生成的密码进行登录,查看MySQL安装时的初始密码
grep "password" /var/log/mysqld.log
复制临时密码,登录MySQL
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
安装MySQL8.0时,设置的密码过于简单(如:123456),不符合MySQL密码规范,会触发一个报错提示:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
所以我们需要调整密码配置策略,但是在配置的时候
mysql> set global validate_password.policy=0;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set global validate_password.length=1;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
所以执行先修改成一个满足规则的密码才行,密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
至此密码修改完成,可以使用新密码登录MySQL服务器。
如果感觉密码过于复杂,可以修改密码验证规则
查看密码验证规则
mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=1;
MySQL 5.7 进行如下设置,即可解决问题:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
MySQL 8.0 执行代码:
mysql> set global validate_password_policy=0;
ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
mysql> set global validate_password_length=1;
ERROR 1193 (HY000): Unknown system variable 'validate_password_length'
如果想把密码设置成简单的,再次执行修改密码操作就可以了
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
systemctl enable mysqld
systemctl daemon-reload
1、查看MySQL字符集
mysql> show variables like '%char%';
如果不是utf8mb4,可以根据下面步骤修改