天天看點

阿裡雲centos7.2安裝mysql_2-2. linux(阿裡雲CentOS7 伺服器) 安裝mysql(8.0.15 )

阿裡雲伺服器上,首先需要設定安全組,否則無法遠端連接配接資料庫

如:

阿裡雲centos7.2安裝mysql_2-2. linux(阿裡雲CentOS7 伺服器) 安裝mysql(8.0.15 )

image.png

阿裡雲centos7.2安裝mysql_2-2. linux(阿裡雲CentOS7 伺服器) 安裝mysql(8.0.15 )

image.png

1. 下載下傳安裝包

(1) 執行如下指令

wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm

(2)檢視是否下載下傳成功

發現 mysql80-community-release-el7-2.noarch.rpm 安裝包,說明成功

[[email protected] software]# ls

mysql80-community-release-el7-2.noarch.rpm node-v10.15.1-linux-x64

2. 安裝資料庫

(1)安裝rpm包

rpm -ivh mysql80-community-release-el7-2.noarch.rpm

(2)安裝 mysql 服務

yum install mysql-server

3. 設定mysql

(1) 設定權限

不知道有沒有用!!

chown mysql:mysql -R /var/lib/mysql

(2) 初始化

mysqld --initialize

4. 驗證 MySQL 安裝

[[email protected] software]# mysqladmin --version

mysqladmin Ver 8.0.15 for Linux on x86_64 (MySQL Community Server - GPL)

5. 登入mysql

需要先啟動mysql

輸入如下指令,然後在/var/log/mysqld.log找到密碼輸入密碼

mysql -u root -p

預設沒有密碼,如果有密碼需要查找預設密碼:

日志路徑: /var/log/mysqld.log

如下所示,日志中有預設密碼:[email protected]: MRoyRxT%9sEt

2019-02-10T14:06:46.685054Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.15) initializing of server in progress as process 11674

2019-02-10T14:06:50.837315Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: MRoyRxT%9sEt

登入成功如下所示

[[email protected] software]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 8.0.15

Copyright (c) 2000, 2019, 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>

6. 更新密碼

不修改密碼不能用其他工具連結

(1) 修改密碼

目前是 Server version: 8.0.15 不同版本修改密碼語句不同

ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密碼';

(2) 選擇性設定密碼永不過期(可選)

ALTER USER 'root' PASSWORD EXPIRE NEVER

(3) 重新整理

flush privileges

7. 通過navicat 連接配接遠端資料庫

連接配接示例:

阿裡雲centos7.2安裝mysql_2-2. linux(阿裡雲CentOS7 伺服器) 安裝mysql(8.0.15 )

image.png

使用 sequel pro 報錯了,對sql了解不深,直接跳過了

阿裡雲centos7.2安裝mysql_2-2. linux(阿裡雲CentOS7 伺服器) 安裝mysql(8.0.15 )

image.png

(1) 登入資料庫

需要先啟動資料庫

mysql -u root -p

(2) 選擇 mysql 資料庫

use mysql;

(3) 在 mysql 資料庫的 user 表中檢視目前 root 使用者的相關資訊

select host, user, authentication_string, plugin from user;

(4) 建立一個允許遠端通路的新使用者

文法:

CREATE USER '使用者名'@'host名稱' IDENTIFIED WITH mysql_native_password BY '密碼';

如:

CREATE USER 'app'@'%' IDENTIFIED WITH mysql_native_password BY 'Mypassworad123';

因為test使用者已經存在,是以在此建立就會失敗,第二次建立app使用者,檢視目前使用者表後可以看到有test和app兩個使用者,如下圖所示:

阿裡雲centos7.2安裝mysql_2-2. linux(阿裡雲CentOS7 伺服器) 安裝mysql(8.0.15 )

image.png

(5) 重新整理

flush privileges

執行完成會出現一個表格

檢視表格中 root 使用者的 host,預設應該顯示的 localhost,隻支援本地通路,不允許遠端通路

如下所示:

阿裡雲centos7.2安裝mysql_2-2. linux(阿裡雲CentOS7 伺服器) 安裝mysql(8.0.15 )

image.png

(6) 删除使用者

不要删除root啊!!!!

Delete FROM mysql.user Where User='user1';

基本指令:

重新開機mysqld

systemctl restart mysqld

設定開機啟動

systemctl enable mysqld

檢視端口号:

show global variables like 'port';

停止mysql :

systemctl stop mysqld

或者

service mysqld stop

啟動mysql:

systemctl start mysqld

或者

service mysqld start

檢視mysql目前運作狀态:

systemctl status mysqld

檢視mysql版本号:

mysqladmin --version

檢視目前有多少個資料庫:

SHOW DATABASES;

檢視目前是哪個使用者:

select current_user();