Linux CentOS7中MySQL安装

Linux CentOS7中MySQL安装

(1) 安装Mysql5.7:

执行命令: rpm -ivh[
_http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-
release-
el7-7.noarch.rpm_](http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-
community-release-el7-7.noarch.rpm)

执行命令: yum install mysql-community-server

(2) 配置Mysql开机自动启动

执行命令: systemctl enable mysqld

(3) 启动MYSQL:

执行命令: systemctl start mysqld

错误排查:

到这里时有些会报一下错

错误显示:

软件包:mysql-community-server-5.7.20-1.el6.x86_64 (mysql57-community)

需要:libsasl2.so.2()(64bit)

您可以尝试添加 –skip-broken 选项来解决该问题

您可以尝试执行:rpm -Va –nofiles –nodigest

解决方法:

1、修改vim /etc/yum.repos.d/mysql-community.repo 源文件

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/

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

2.yum install mysql-community-server #再次安装mysql

3.systemctl start mysqld #启动mysql
4.systemctl status mysqld #查看mysql启动状态

(4)安装完成后,开始修改初始密码。

执行命令查看文件:

cat /var/log/mysqld.log

找到内容为:A temporary password is generated for root@localhost: h?j39ui0>bEp

后面的随机字符串,即为初始密码,使用初始密码登陆:mysql -hlocalhost -uroot -p ,然后输入随机密码。登陆到msyql客户端命令行。

alter user 'root'@'localhost' identified by 'Password01!';   

如果想设置简单密码,则需要修改密码策略。如:修改策略(将策略要求置为LOW,长度要求置为1)

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

修改策略后,如果想修改成123456这种简单密码,可以执行:

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

备注:其它修改密码的方法

修改MySQL密码方式:
法1:update user set authentication_string=password('123abc') where user='root';
法2:set password=password('newpassword');
法3:alter user root@'localhost' identified by 'oracle';
法4:在shell下使用MySQL工具:mysqladmin -uroot -poldpassword pasword "newpassword"

(5)设置远程访问,登陆mysql客户端后,执行:

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

如需要设置权限 ,如# IP为172.16.52.225的电脑可以使用sindrol用户,密码为abc001远程访问数据库testdb的所有表!可以这样:

GRANT ALL PRIVILEGES ON testdb.* TO 'sindrol'@'172.16.52.225'  IDENTIFIED BY 'abc001' WITH GRANT OPTION; 
flush privileges;

Linux CentOS7中MySQL安装
https://www.dearcloud.cn/2017/09/26/20200310-cnblogs-old-posts/20170926-LinuxCentos7中MySql安装/
作者
宋兴柱
发布于
2017年9月26日
许可协议