【服务器环境搭建】之 Centos安装mysql教程

卸载原有mysql

检查是否已经安装Mysql

rpm -qa | grep mysql

卸载已经安装的Mysql

## 删除mysql相关目录
find / -name mysql |xargs rm -rf

安装新的mysql

安装yum源

yum localinstall mysql57-community-release-el7-8.noarch.rpm

安装mysql服务

yum install -y mysql-community-server

检查mysql安装结果

[root@baimaduhe src]# mysql -V
mysql  Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using  EditLine wrapper

启动Mysql 服务

systemctl start mysqld

设置Mysql 开机启动

systemctl start mysqld

获取Mysql 初始密码

[root@baimaduhe src]# grep 'temporary password' /var/log/mysqld.log
2020-01-17T15:12:08.755778Z 1 [Note] A temporary password is generated for root@localhost: ;QsQkdLBl6kR

连接到mysql

[root@baimaduhe src]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

配置mysql

将密码强度设置为低

学习用为了方便才这样设置,生产环境请勿这样设置

 set global validate_password_policy=LOW;

修改mysql

mysql> ALTER USER USER() IDENTIFIED BY 'new_password';

允许远程访问

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

刷新配置

FLUSH PRIVILEGES;

远程登录mysql

mycli -u root -p<your_password> -h <service ip> -P 3306

参考资料

  • https://www.cnblogs.com/123hll/p/9633422.html
  • https://blog.csdn.net/muziljx/article/details/81541896
  • https://www.mysql.com/
发布了17 篇原创文章 · 获赞 4 · 访问量 2万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章