centos7下安装mysql5.7(rpm)

原创     发表于 2020-10-14 12:08     阅读 88  

Centos7离线安装mysql 
安装包下载 
https://dev.mysql.com/downloads/mysql/ 
根据系统版本下载


安装新版mysql前,需将系统自带的mariadb-lib卸载

[root@hadoop ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@hadoop ~]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
[root@hadoop ~]# rpm -qa|grep mariadb

tar -xvf mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar

四 使用 rpm 命令安装MySql组件 
使用命令rpm -ivh {-file-name}进行安装操作。

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

[root@localhost home]#rpm -ivh mysql-community-common-8.0.20-1.el7.x86_64.rpm
[root@localhost home]#rpm -ivh mysql-community-libs-8.0.20-1.el7.x86_64.rpm
[root@localhost home]#rpm -ivh mysql-community-client-8.0.20-1.el7.x86_64.rpm

[root@localhost]cd /home/mysqlfiles/
[root@localhost mysqlfiles]# rpm -Uvh ./*.rpm --nodeps --force

[root@localhost]#cd /home/
[root@localhost home]#rpm -ivh mysql-community-server-8.0.20-1.el7.x86_64.rpm

五 登录并创建MySql密码 
1 启动MySql 
安装完后,使用命令 service mysqld start 或 systemctl start mysqld.service 启动MySQL服务。(如果mysql服务无法启动,就重启一下系统)

 [root@localhost home]#systemctl start mysqld.service

systemctl start mysqld.service 启动mysql 
systemctl status mysqld.service 查看mysql状态 
systemctl stop mysqld.service 关闭mysql

查看mysql进程 ps -ef|grep mysql 
查看3306端口 netstat -anop|grep 3306

登录到mysql,更改root用户的密码 
命令可以查看初始密码

[root@localhost home]#grep 'temporary password' /var/log/mysqld.log

2.修改变量

注意到8.0 比5.7多了带“.”的变量导致只设置一半是不够的,要想在高版本使用简单的密码,需要做这样设置:

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)

然后再执行如下命令设置新的简单密码就OK了

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.02 sec)


mysql> use mysql;
mysql> select user,host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+

mysql>INSERT INTO `mysql`.`user`(`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) VALUES ('%', 'root', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B', 'N', '2019-10-22 18:01:28', NULL, 'N');
Query OK, 1 row affected (0.01 sec)

mysql> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host      | user             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| %         | root             | mysql_native_password | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B                              |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | caching_sha2_password | $A$005$/w, 
                                                                   L#O
 woiM^QNfwz8vQlsL8iwhyPqe6fuyAITukKGsuBhqBY7y3SXD |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.01 sec)

重启才能生效

关闭mysql

[root@localhost ~]# systemctl stop mysqld.service  

启动mysql

[root@localhost ~]# systemctl start mysqld.service

插入了远程登录: 
在远程机器上测试远程连接: mysql -h192.168.0.241 -uroot -p

设置mysql开机启动 
// 检查是否已经是开机启动 
systemctl list-unit-files | grep mysqld 


这里写图片描述

// 开机启动 
systemctl enable mysqld.service