Linux安装MySQL5.7(详细而简单)


vim /etc/yum.repos.d/mysql-community.repo

将以下代码复制进去

# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

安装

yum install mysql-community-server

权限设置

chown mysql:mysql -R /var/lib/mysql

初始化

mysqld --initialize

启动

systemctl start mysqld

如果报错:

Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

Do this and star mysql again

rm -rf /var/lib/mysql

查看运行状态

systemctl status mysqld

获取默认密码并登陆MySQL

grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
use mysql;   #这一步如果报错,类似于下面这样,直接跳转下一步
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

重置密码(密码尽量包含大小写以及数字,否则可能设置不成功,切记:复杂

alter user 'root'@'localhost' identified by 'Abc123';

开启远程登录(如果需要远程连接的话)

select user,host from user;

修改前

user host
mysql.session localhost
mysql.sys localhost
root localhost
update user set host='%' where user='root';

修改后

user host
mysql.session localhost
mysql.sys localhost
root %

刷新权限

flush privileges;

其他参考命令

systemctl stop firewalld.service                              #停止firewall
systemctl disable firewalld.service                           #禁止firewall开机启动
firewall-cmd --zone=public --add-port=3306/tcp --permanent    #开放端口 
firewall-cmd --zone=public --remove-port=3306/tcp --permanent #关闭端口
firewall-cmd --reload                                         #重新载入以生效
firewall-cmd --list-ports                                     #查看开放端口列表

文章作者: Jack Li
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Jack Li !
评论
  目录