栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Centos7安装MySQL5.x版本详细步骤

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Centos7安装MySQL5.x版本详细步骤

1、下载地址

MySQL :: Download MySQL Community Server (Archived Versions)https://downloads.mysql.com/archives/community/

2、使用 yum

命令安装MySql组件

使用命令yum install -y {-file-name}进行安装操作。

按照依赖关系依次安装rpm包 依赖关系依次为common→libs→client→server!!!

yum install mysql-community-common-5.7.35-1.el7.x86_64.rpm
yum install -y mysql-community-libs-5.7.35-1.el7.x86_64.rpm
yum install -y mysql-community-client-5.7.35-1.el7.x86_64.rpm
yum install -y mysql-community-server-5.7.35-1.el7.x86_64.rpm

在安装 mysql-community-libs-5.7.35-1.el7.x86_64.rpm 时有可能会报错:mysql依赖错误:

 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.35-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.35-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.35-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64

 解决办法:

rpm -qa|grep mysql
yum remove -y mysql-libs

或者
rpm -qa | grep mariadb-libs
yum remove -y mariadb-libs

3、启停mysql并开机自启

#启动 mysql
systemctl start mysqld

#重启 mysql
systemctl restart mysqld

#停止 mysql
systemctl stop mysqld 

#设置 mysql 开机启动
systemctl enable mysqld

4、mysql常用文件路径

/etc/my.cnf   这是mysql的主配置文件
/var/lib/mysql   mysql数据库的数据库文件存放位置
/var/logs/mysqld.log  数据库的日志输出存放位置

5、进入mysql

此时如果要进入MySQL得找出root用户的密码,输入命令

grep "password" /var/log/mysqld.log

得到密码后,登录mysql,输入命令

mysql -uroot -p

此时,你需要给你的MySql重新设置密码,因为MySQL默认的就是必须修改密码后才能操作数据库。

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

 以修改密码设置规范,毕竟你不登录你就不能修改规范。

总之呢,我们先将密码设置成比较复杂的就好,比如 Abc@1234567890...,先登录了再说。

alter user 'root'@'localhost' identified by 'Abc@1234567890';

 查看密码规范

SHOW VARIABLES LIKE 'validate_password%';

 密码的长度是由validate_password_length决定的,而validate_password_length的计算公式是:

validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)

这时候我们将密码设置规范修改一下:

set global validate_password_policy=0;       # 关闭密码复杂性策略
set global validate_password_length=4;      # 设置密码最低长度为4


 

6、然后进行密码重置

mysql_secure_installation命令:
[root@mysql5 ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: YES)
[root@mysql5 ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: YES)
[root@mysql5 ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : n

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

7、授权远程登录

use mysql;
select user,host,grant_priv from user;
create user 'root'@'%' identified by 'YOU_PASSWORD';

更新授权数据库:

update user set grant_priv='Y' where user='root';
flush privileges;

现在就能给用户赋予权限了

授权登录
登录mysql之后执行

GRANT ALL ON *.* TO 'root'@'%';

 如果使用客户端连接提示了plugin caching_sha2_password错误,这是因为MySQL8.0的密码策略默认为caching_sha2_password

 使用命令修改策略

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'XXXXXXXXXXXXXX';

即可远程登录了!!!
 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/395620.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号