1. 程式人生 > >【Mysql】安裝

【Mysql】安裝

author:咔咔

wechat:fangkangfk

 

這裡就是會遇到設定密碼問題,這個問題,我在下面文章已經寫了,可以看,如果是不需要修改密碼的,就不用管了

https://mp.csdn.net/postedit/84632058

 

 

 

 從CentOS 7.0釋出以來,yum源中開始使用mariadb來代替MySQL的安裝。即使你輸入的是yum install mysql , 顯示的也是mariadb的安裝內容。

  首先先解除安裝mariadb。

  檢查mariadb是否已安裝

1

2

[[email protected] ~]# yum list installed | grep mariadb 

mariadb-libs.x86_64                  1:5.5.56-2.el7                    @anaconda

  全部解除安裝

 解除安裝預設安裝的mariadb

 

安裝Mysql

  一、下載安裝官方提供的yum rpm包

  下載網頁:https://dev.mysql.com/downloads/repo/yum/

  點選Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package後面的download,進入新的頁面點選No thanks, just start my download.就可以看到下載源地址了。

  下載wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

1

wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

  安裝rpm包

1

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

  檢查mysql的yum源是否安裝成功:yum repolist enabled | grep "mysql.*-community.*" 

1

2

3

4

[[email protected] src]# yum repolist enabled | grep "mysql.*-community.*"

mysql-connectors-community/x86_64       MySQL Connectors Community           51

mysql-tools-community/x86_64            MySQL Tools Community                63

mysql80-community/x86_64                MySQL 8.0 Community Server           17

  二、使用yum install mysql-server安裝(這裡會有點慢)

1

yum -y  install mysql-server

 檢視版本資訊

 

  三、啟動mysql

1

2

[[email protected] ~]# service mysqld start 

Redirecting to /bin/systemctl start mysqld.service

  四、使用初始密碼登入

1

2

[[email protected] ~]# cat /var/log/mysqld.log|grep 'A temporary password'

2018-05-18T02:01:17.558742Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: belPU>iuF4*H

  最後一行冒號後面的部分belPU>iuF4*H就是初始密碼。 

  五、mysql5.7開始對root密碼複雜性要求很高,必須有數字、字母大小寫、符號(應該是需要8位以上),這裡我麼還查show databases;不了。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

[[email protected] ~]# 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.11

 

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> show databases;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

  只需要把root密碼更改的複雜一些即可。

  更改密碼方法:

1

2

3

4

5

6

7

8

9

解決辦法

1、 修改使用者密碼

mysql> alter user 'root'@'localhost' identified by 'youpassword'

 

或者(下面這個只能修改當前登入的使用者密碼)      

 

mysql> set password=password("youpassword");

2、重新整理許可權

mysql> flush privileges;

  示例

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

mysql> alter user 'root'@'localhost' identified by 'qA123,./';

Query OK, 0 rows affected (0.10 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.01 sec)

  重啟mysqld服務。

1

[[email protected] ~]# systemctl restart mysqld.service

  

1

2

3

4

5

6

7

8

常用的命令:

 

systemctl start mysqld    #啟動mysqld

systemctl stop mysqld    #停止mysqld

systemctl restart mysqld    #重啟mysqld

systemctl enable mysqld   #設定開機啟動

 

systemctl status mysqld    #檢視 MySQL Server 狀態