CentOS7 線上安裝mysql5.7
1. 從官網找到自己需要的mysql版本 我使用mysql5.7
這裡有官方安裝說明
或 使用 https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/ 連結
找到
獲取這個連結
我使用的連結 http://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
2. 使用wget 獲取rpm包
[[email protected]_0_10_centos ~]# wget http://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm --2018-10-05 18:54:49-- http://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm Resolving repo.mysql.com (repo.mysql.com)... 23.2.3.81 Connecting to repo.mysql.com (repo.mysql.com)|23.2.3.81|:80... 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-10-05 18:54:49 (83.4 MB/s) - ‘mysql57-community-release-el7-8.noarch.rpm’ saved [9116/9116]
或參考官方指導 https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/#repo-qg-yum-installing
3. 安裝 mysql community-release
[[email protected]_0_10_centos ~]# yum -y install mysql57-community-release-el7-8.noarch.rpm Loaded plugins: fastestmirror, langpacks Examining mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch Marking 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 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!
4. 安裝mysql 相關 服務
[[email protected]_0_10_centos ~]# yum search mysql-com
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
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): mysql57-community/x86_64/primary_db | 152 kB 00:00:00
(2/3): mysql-connectors-community/x86_64/primary_db | 26 kB 00:00:01
(3/3): mysql-tools-community/x86_64/primary_db | 45 kB 00:00:01
=============================== N/S matched: mysql-com ================================
mysql-community-client.i686 : MySQL database client applications and tools
mysql-community-client.x86_64 : MySQL database client applications and tools
mysql-community-common.i686 : MySQL database common files for server and client libs
mysql-community-common.x86_64 : MySQL database common files for server and client libs
mysql-community-devel.i686 : Development header files and libraries for MySQL database
: client applications
mysql-community-devel.x86_64 : Development header files and libraries for MySQL
: database client applications
mysql-community-embedded.i686 : MySQL embedded library
mysql-community-embedded.x86_64 : MySQL embedded library
mysql-community-embedded-compat.i686 : MySQL embedded compat library
mysql-community-embedded-compat.x86_64 : MySQL embedded compat library
mysql-community-embedded-devel.i686 : Development header files and libraries for MySQL
: as an embeddable library
mysql-community-embedded-devel.x86_64 : Development header files and libraries for
: MySQL as an embeddable library
mysql-community-libs.i686 : Shared libraries for MySQL database client applications
mysql-community-libs.x86_64 : Shared libraries for MySQL database client applications
mysql-community-libs-compat.i686 : Shared compat libraries for MySQL 5.6.25 database
: client applications
mysql-community-libs-compat.x86_64 : Shared compat libraries for MySQL 5.6.37 database
: client applications
mysql-community-release.noarch : MySQL repository configuration for yum
mysql-community-server.x86_64 : A very fast and reliable SQL database server
mysql-community-test.x86_64 : Test suite for the MySQL database server
Name and summary matches only, use "search all" for everything.
5. 安裝 mysql 伺服器
[[email protected]_0_10_centos ~]# yum -y install mysql-community-server.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.23-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.23-1.el7 for package: mysql-community-server-5.7.23-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.23-1.el7.x86_64
。。。
。。。
。。。
省略
Dependency Installed:
mysql-community-client.x86_64 0:5.7.23-1.el7
mysql-community-common.x86_64 0:5.7.23-1.el7
numactl-libs.x86_64 0:2.0.9-7.el7
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
6. 啟動MySQL伺服器
[[email protected]_0_10_centos ~]# systemctl start mysqld.service
官方指導 7版本 啟動伺服器有區別
檢查MySQL伺服器的狀態
[[email protected]_0_10_centos ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2018-10-05 19:08:06 CST; 52s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 29471 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 29177 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 29474 (mysqld)
CGroup: /system.slice/mysqld.service
└─29474 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pi...
Oct 05 19:07:55 VM_0_10_centos systemd[1]: Starting MySQL Server...
Oct 05 19:08:06 VM_0_10_centos systemd[1]: Started MySQL Server.
顯示為 Active: active (running) since Fri 2018-10-05 19:08:06 CST; 52s ago 代表正常啟動
官方提示
7. 檢視初始化密碼
從MySQL 5.7開始 mysql會自動初始化一個密碼 使用者第一次登入 可在錯誤日誌裡檢視
使用一下命令檢視
[[email protected]_0_10_centos ~]# grep 'temporary password' /var/log/mysqld.log
2018-10-05T11:07:57.372256Z 1 [Note] A temporary password is generated for [email protected]: :vqDKto/r1Vr
:vqDKto/r1Vr這是我的初始化密碼([email protected]: 後面)
8.使用初始化密碼進入資料庫
[[email protected]_0_10_centos ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.23
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
9.修改密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '簡單密碼';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '複雜密碼';
Query OK, 0 rows affected (0.00 sec)
密碼過於簡單會修改失敗
你以為 已經安好了麼 那你可以遠端連線一下試試看
使用遠端連結會出現 1130 錯誤 (解決如下)
這是因為mysql 資料庫 只對localhost 開啟訪問
10. 切換使用mysql資料庫
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
檢視的user 表如下
mysql> select u.Host, u.User from user u;
+-----------+---------------+
| Host | User |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
可以看到root使用者只對localhost開放
11. 修改root 使用者對應的Host 為 % (把localhost 修改為 %)
mysql> update user u set u.Host = '%' where u.User = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
12.退出mysql重啟 mysql服務即可完成安裝
mysql> exit
Bye
[[email protected]_0_10_centos ~]# systemctl restart mysqld.service
[[email protected]_0_10_centos ~]#
安裝完成
End~