CentOS7安装MySQL5.7以及修改密码

CentOS7安装mysql


[root@bd005 ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
--2018-11-08 18:43:55--  http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm [following]
--2018-11-08 18:43:56--  https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm [following]
--2018-11-08 18:43:57--  https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.50.35.125
Connecting to repo.mysql.com (repo.mysql.com)|23.50.35.125|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9116 (8.9K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-8.noarch.rpm’

100%[====================================================================================================================================================================================================================================>] 9,116       --.-K/s   in 0s      

2018-11-08 18:43:57 (130 MB/s) - ‘mysql57-community-release-el7-8.noarch.rpm’ saved [9116/9116]

[root@bd005 ~]# ll
total 20
-rw-------. 1 root root 1276 Aug 18  2017 anaconda-ks.cfg
-rw-r--r--. 1 root root  837 Dec  7  2017 initialize_server.sh
-rw-r--r--  1 root root 9116 Apr 11  2016 mysql57-community-release-el7-8.noarch.rpm
[root@bd005 ~]# mv mysql57-community-release-el7-8.noarch.rpm /usr/local/softs/
[root@bd005 ~]# cd /usr/local/softs/
[root@bd005 softs]# ll
total 9416
-rw-r--r-- 1 root root 9625824 Nov  6 17:37 apache-tomcat-8.5.34.tar.gz
-rw-r--r-- 1 root root    9116 Apr 11  2016 mysql57-community-release-el7-8.noarch.rpm
drwxr-xr-x 9 root root     220 Nov  8 17:34 tomcat8534
[root@bd005 softs]# mkdir rpms
[root@bd005 softs]# mv mysql57-community-release-el7-8.noarch.rpm rpms/
[root@bd005 softs]# ll
total 9404
-rw-r--r-- 1 root root 9625824 Nov  6 17:37 apache-tomcat-8.5.34.tar.gz
drwxr-xr-x 2 root root      56 Nov  8 18:44 rpms
drwxr-xr-x 9 root root     220 Nov  8 17:34 tomcat8534
[root@bd005 softs]# yum localinstall rpms/mysql57-community-release-el7-8.noarch.rpm
Loaded plugins: fastestmirror
Examining rpms/mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch
Marking rpms/mysql57-community-release-el7-8.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                                 Arch                                                 Version                                             Repository                                                                             Size
==============================================================================================================================================================================================================================================================================
Installing:
 mysql57-community-release                                               noarch                                               el7-8                                               /mysql57-community-release-el7-8.noarch                                               8.2 k

Transaction Summary
==============================================================================================================================================================================================================================================================================
Install  1 Package

Total size: 8.2 k
Installed size: 8.2 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql57-community-release-el7-8.noarch                                                                                                                                                                                                                     1/1 
  Verifying  : mysql57-community-release-el7-8.noarch                                                                                                                                                                                                                     1/1 

Installed:
  mysql57-community-release.noarch 0:el7-8                                                                                                                                                                                                                                    

Complete!
[root@bd005 softs]# yum install mysql-community-server
Loaded plugins: fastestmirror
mysql-connectors-community                                                                                                                                                                                                                             | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                                                                                                                                  | 2.5 kB  00:00:00     
mysql57-community                                                                                                                                                                                                                                      | 2.5 kB  00:00:00     
(1/3): mysql-connectors-community/x86_64/primary_db                                                                                                                                                                                                    |  29 kB  00:00:00     
(2/3): mysql-tools-community/x86_64/primary_db                                                                                                                                                                                                         |  48 kB  00:00:00     
(3/3): mysql57-community/x86_64/primary_db                                                                                                                                                                                                             | 162 kB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.24-1.el7 for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: net-tools for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.24-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.24-1.el7 will be installed
---> Package net-tools.x86_64 0:2.0-0.22.20131004git.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.24-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.24-1.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                                   Arch                                                 Version                                                                 Repository                                                       Size
==============================================================================================================================================================================================================================================================================
Installing:
 mysql-community-libs                                                      x86_64                                               5.7.24-1.el7                                                            mysql57-community                                               2.2 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-libs-compat                                               x86_64                                               5.7.24-1.el7                                                            mysql57-community                                               2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-server                                                    x86_64                                               5.7.24-1.el7                                                            mysql57-community                                               165 M
Installing for dependencies:
 mysql-community-client                                                    x86_64                                               5.7.24-1.el7                                                            mysql57-community                                                24 M
 mysql-community-common                                                    x86_64                                               5.7.24-1.el7                                                            mysql57-community                                               274 k
 net-tools                                                                 x86_64                                               2.0-0.22.20131004git.el7                                                base                                                            305 k

Transaction Summary
==============================================================================================================================================================================================================================================================================
Install  3 Packages (+3 Dependent packages)

Total download size: 194 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY                                                                            ] 362 kB/s | 280 kB  00:09:08 ETA 
Public key for mysql-community-common-5.7.24-1.el7.x86_64.rpm is not installed
(1/6): mysql-community-common-5.7.24-1.el7.x86_64.rpm                                                                                                                                                                                                  | 274 kB  00:00:01     
(2/6): mysql-community-libs-5.7.24-1.el7.x86_64.rpm                                                                                                                                                                                                    | 2.2 MB  00:00:02     
(3/6): mysql-community-libs-compat-5.7.24-1.el7.x86_64.rpm                                                                                                                                                                                             | 2.0 MB  00:00:02     
(4/6): net-tools-2.0-0.22.20131004git.el7.x86_64.rpm                                                                                                                                                                                                   | 305 kB  00:00:01     
(5/6): mysql-community-server-5.7.24-1.el7.x86_64.rpm                                                                                                                                                                                                  | 165 MB  00:01:57     
(6/6): mysql-community-client-5.7.24-1.el7.x86_64.rpm                                                                                                                                                                                                  |  24 MB  00:04:28     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                         739 kB/s | 194 MB  00:04:28     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <[email protected]>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-8.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.24-1.el7.x86_64                                                                                                                                                                                                                 1/7 
  Installing : mysql-community-libs-5.7.24-1.el7.x86_64                                                                                                                                                                                                                   2/7 
  Installing : mysql-community-client-5.7.24-1.el7.x86_64                                                                                                                                                                                                                 3/7 
  Installing : net-tools-2.0-0.22.20131004git.el7.x86_64                                                                                                                                                                                                                  4/7 
  Installing : mysql-community-server-5.7.24-1.el7.x86_64                                                                                                                                                                                                                 5/7 
  Installing : mysql-community-libs-compat-5.7.24-1.el7.x86_64                                                                                                                                                                                                            6/7 
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                                                                                                                                         7/7 
  Verifying  : net-tools-2.0-0.22.20131004git.el7.x86_64                                                                                                                                                                                                                  1/7 
  Verifying  : mysql-community-libs-compat-5.7.24-1.el7.x86_64                                                                                                                                                                                                            2/7 
  Verifying  : mysql-community-libs-5.7.24-1.el7.x86_64                                                                                                                                                                                                                   3/7 
  Verifying  : mysql-community-client-5.7.24-1.el7.x86_64                                                                                                                                                                                                                 4/7 
  Verifying  : mysql-community-server-5.7.24-1.el7.x86_64                                                                                                                                                                                                                 5/7 
  Verifying  : mysql-community-common-5.7.24-1.el7.x86_64                                                                                                                                                                                                                 6/7 
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                                                                                                                                         7/7 

Installed:
  mysql-community-libs.x86_64 0:5.7.24-1.el7                                            mysql-community-libs-compat.x86_64 0:5.7.24-1.el7                                            mysql-community-server.x86_64 0:5.7.24-1.el7                                           

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.24-1.el7                                              mysql-community-common.x86_64 0:5.7.24-1.el7                                              net-tools.x86_64 0:2.0-0.22.20131004git.el7                                             

Replaced:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                                                                                                                                                                                                          

Complete!
[root@bd005 softs]# systemctl start mysqld
[root@bd005 softs]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2018-11-08 18:58:01 CST; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1276 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 1203 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1280 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─1280 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Nov 08 18:57:57 bd005 systemd[1]: Starting MySQL Server...
Nov 08 18:58:01 bd005 systemd[1]: Started MySQL Server.
[root@bd005 softs]# grep 'temporary password' /var/log/mysqld.log //生成临时密码
2018-11-08T10:57:58.087434Z 1 [Note] A temporary password is generated for root@localhost: /GUeg#cGo3MU
[root@bd005 softs]# mysql -uroot -p/GUeg#cGo3MU
[root@bd005 softs]# 
mysql>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '/GUeg#cGo3MU';
Query OK, 0 rows affected (0.00 sec)
mysql> set password for 'root'@'localhost'=password('/GUeg#cGo3MU');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all on *.* to 'root'@'%' identified by '/GUeg#cGo3MU';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit;
Bye
[root@bd005 softs]# mysql -uroot -p/GUeg#cGo3MU
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
rows in set (0.00 sec)
mysql> quit;
Bye
[root@bd005 softs]# vim /etc/my.cnf (在[mysqld]下添加character_set_server=utf8和init_connect='SET NAMES utf8')
[root@bd005 softs]# systemctl restart mysqld

修改临时密码:
[root@bd005 softs]# vim /etc/my.cnf (在[mysqld]下添加
skip-grant-tables=1跳过权限检查)
[root@bd005 softs]# systemctl restart mysqld
[root@bd005 softs]# mysql -uroot
mysql> use mysql;
mysql> updateuserset authentication_string = password('123456'),password_last_changed=now() whereuser='root';
mysql> quit;
Bye
[root@bd005 softs]# vim /etc/my.cnf (找[mysqld]下的
skip-grant-tables=1删除或注释掉)
[root@bd005 softs]# systemctl restart mysqld //重启mysql
[root@bd005 softs]# mysql -uroot -p123456 //用新密码登录即可


猜你喜欢

转载自www.cnblogs.com/mengyao/p/9956745.html
今日推荐