centos7安装mysql5.7.30

1.下载mysql的repo源 这个安装的mysql5.7.30

//依次执行
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 
[root@localhost src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm 
[root@localhost src]#  yum -y install mysql-server 

2.配置 my.cnf vim /etc/my.cnf

[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=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server_id = 1
expire_logs_days = 3
 
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

character-set-server=utf8
init_connect='SET NAMES utf8'

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

3.启动Mysql服务

systemctl start mysqld
或者
service mysqld restart

4.设置开机启动

systemctl enable mysqld
systemctl daemon-reload

6.修改root本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。

[root@localhost ~]# grep "password" /var/log/mysqld.log 

centos7安装mysql5.7.30_第1张图片
接着进入MySQL:

mysql -u root -p
//输入查询到的密码
Enter password:

修改密码策略(将策略要求置为LOW,长度要求置为1)

set global validate_password_policy=0;
set global validate_password_length=1;

接着修改密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

7.设置允许远程登录

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

8.退出Mysql,开放3306端口;

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

9.参考文档
1.https://blog.csdn.net/z13615480737/article/details/78906598
2.https://www.cnblogs.com/cainiaoxiaoxie/p/12622241.html

你可能感兴趣的:(mysql)