1. 程式人生 > >阿里雲 ESC 伺服器安裝 mysql linux安裝mysql

阿里雲 ESC 伺服器安裝 mysql linux安裝mysql

1、更新伺服器系統確保是最新的

[[email protected] server]# yum -y update

如果顯示以下內容說明已經更新完成

Complete!

2、重啟伺服器

[[email protected] server]# reboot

3、檢查是否已經安裝mysql服務

[[email protected] server]# yum list installed | grep mysql

如果顯示以下內容表示沒有安裝

-bash: gerp: command not found

4、下載mysql的安裝包

[[email protected]

server]# rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

5、安裝mysql

安裝MySql

[[email protected] server]# yum install -y mysql-server

[[email protected] server]# yum install mysql-community-server

如果顯示以下內容表示安裝成功

Complete!

6、設定開機啟動Mysql

[[email protected]

server]# systemctl enable mysqld.service

7、檢視服務是否加入開機自動啟動

[[email protected] server]# systemctl list-unit-files | grep mysqld

8、檢視mysql的預設臨時密碼

[[email protected] server]# systemctl list-unit-files | grep mysqld

2018-11-01T10:37:02.768355Z 1 [Note] A temporary password is generated for [email protected]

: F9qP5l+NQnR?

9、root使用者登入mysql資料庫

[[email protected] server]# mysql -u root -p 

Enter password: 

輸入密碼登入成功

Server version: 5.7.24 MySQL Community Server (GPL)

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> 

10、修改root使用者密碼

mysql> use  mysql;----切換到mysql db

mysql> UPDATE user SET authentication_string = PASSWORD('newpass') WHERE user = 'root';---新版本mysql執行

mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';---老版本mysql執行

mysql> flush privileges;---命令立即執行生效

網上查了一下據說5.7 版本password 欄位改成authentication_string  password

12、root使用者登入密碼忘記,登入報錯

[[email protected] etc]# mysql -u root -p Enter password:  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

查詢mysql的啟動檔案

[[email protected] etc]# whereis  my

my: /etc/my.cnf

修改my.cnf啟動引數,在檔案的最後增加,mysql啟動引數—— --skip-grant-tables。啟動 mysql時不啟動授權表 grant-tables

[[email protected] etc]# vi /etc/my.cnf skip-grant-tables

[[email protected] etc]# :wq

vi模式Enter進入,按“i”鍵,編輯檔案,按“esc”鍵,輸入:wq寫入儲存退出,:q 不儲存退出

[[email protected] etc]# :wq

重啟mysql服務

[[email protected] etc]# service mysqld restart

登入mysql

[[email protected] etc]# mysql

修改root使用者密碼同第10、

密碼修改成功後需要進入vi模式下重新編輯/etc/my.cnf去掉增加的skip-grant-tables 重啟mysql服務,就可以用密碼登入了