服务器平台: VMware® Workstation 15 Pro(15.5.2 build-15785246) CentOS7(3.10.0-957.el7.x86_64)
Part1.安装
官网参考
1.利用 Yum Repository来安装,Mysql版本5.7.x
yum -y
install mysql57-community-release-el7-10.noarch.rpm
说明,如果报错没有安装包:
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
再次执行上一条命令。
2.安装MySQL服务器
yum -y
install mysql-community-server
Part2.配置
1.启动mysql
systemctl start mysqld.service
systemctl start mysqld
sudo service mysqld start
2.查看运行状态
systemctl status mysqld.service
sudo service mysqld status
3.查看随机密码
grep "password" /var/log/mysqld.log
sudo grep 'temporary password' /var/log/mysqld.log
4.登陆mysql
myslq -uroot -p
5.修改密码(mysql 命令)
ALTER USER
'root'@
'localhost' IDENTIFIED BY
'MyNewPass4!';
6.开启远程访问(mysql 命令)
grant all privileges on *.* to
'root'@
'192.168.0.1' identified by
'yourpwd' with grant option
;
说明:ip可用%替代,表示所有。yourpwd代表你远程登陆数据库的密码。
刷新
flush privileges
;
7.设置字符集
1)查看默认字符集
mysql
> status
--------------
mysql Ver 14.14 Distrib 5.7.32,
for Linux
(x86_64
) using EditLine wrapper
Connection id: 4
Current database:
Current user: root@localhost
SSL: Not
in use
Current pager: stdout
Using outfile:
''
Using delimiter:
;
Server version: 5.7.32 MySQL Community Server
(GPL
)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 hour 30 min 12 sec
Threads: 1 Questions: 13 Slow queries: 0 Opens: 113 Flush tables: 1 Open tables: 106 Queries per second avg: 0.002
--------------
2)退出mysql,修改/etc/my.cnf配置文件
[client
]
default-character-set
=utf8
[mysqld
]
character-set-server
=utf8
collation-server
=utf8_general_ci
说明:
离开 mysql 环境快捷键:ctrl + D
3)验证,进入 mysql 输入status查看。
8.开放端口
如果防火墙未开启,请忽略。
firewall-cmd --add-port
=3306/tcp --permanent
说明:
--permanent表示存储到配置文件中,配置不会立即生效--zone用于指定所要设置的zone,如果不指定则使用默认zone。查询当前系统默认为public,所以无需--zone=public。
Part3. 附录
1.密码相关的 MySQL 命令
修改默认密码复杂度
set global validate_password_policy
=LOW
;
修改默认密码长度
set global validate_password_length
=6
;
命令查看mysql默认密码复杂度
SHOW VARIABLES LIKE
'validate_password%';