CentOS 7.6下安装MySQL

CentOS 7.6下安装MySQL

准备工作

  • CentOS 7.6
  • MySQL5.7

下载MYSQL

  1. 下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  1. 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm  
  1. 检查mysql源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*
  1. 修改 vim /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。

安装MYSQL

shell> yum install mysql-community-server

启动MYSQL服务

shell> systemctl start mysqld

开机启动服务

shell> systemctl enable mysqld
shell> systemctl daemon-reload

修改root本地登录密码

  1. 查看MYSQL密码
shell> grep 'temporary password' /var/log/mysqld.log

image.png

  1. 连接mysql
shell> mysql -uroot -p
  1. 修改密码[注意:后面的分号一定要跟上]
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

或者:

mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); 
mysql> show variables like '%password%';

添加远程用户

mysql> GRANT ALL PRIVILEGES ON *.* TO 'caoxiaobo'@'%' IDENTIFIED BY 'Caoxiaobo0917!' WITH GRANT OPTION;
# Java  LINUX  MYSQL 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×