Centos操作系統(七)-MySql安裝與使用

MySql安裝與使用

一、安裝

1、下載

[root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-7.noarch.rpm

2、將下載的文件引入你的repo庫中

[root@localhost ~]# rpm -ivh mysql57-community-release-el7-7.noarch.rpm

3、安裝MySQL數據庫服務器

[root@localhost ~]# yum -y install mysql-community-server

4、啓動mysql服務

[root@localhost ~]# systemctl restart mysqld

5、查詢root密碼

[root@localhost ~]# grep “password” /var/log/mysqld.log
2018-10-08T05:22:38.311433Z 1 [Note] A temporary password is generated for root@ localhost: RglpQQrpr9#W

6、root賬戶登錄MySql

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
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>

7、修改密碼

輸入初始密碼,此時不能做任何事情,因爲MySQL默認必須修改密碼之後才能操作數據庫修改密碼命令:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Houjianjun@1234';
Query OK, 0 rows affected (0.00 sec)

1)、查看MySQL完整的初始密碼規則


mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.01 sec)

2)、修改MySQL默認策略和密碼長度

①修改密碼策
因爲當前的密碼太複雜不方便後期做實驗,所以使用命令修改密碼策略兩種方式:
mysql> set global validate_password_policy=0;
如何在Centos7下安裝MySQL5.7
mysql> set global validate_password_policy=LOW;
如何在Centos7下安裝MySQL5.7
注:密碼策略分四種
1、OFF(關閉) 2、LOW(低) 3、MEDIUM(中) 4、STRONG(強)
②修改密碼長度
上邊改完策略之後我們在改長度 mysql> SET GLOBAL validate_password_length=4;
修改爲簡單密碼:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1234';

8、初始化數據庫

[root@localhost ~]# mysql_secure_installation
Securing the MySQL server deployment.
#輸入密碼
Enter password for user root:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 50
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) :
 ... skipping.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
 ... skipping.
All done!

9、開啓遠程連接

mysql> grant all privileges  on *.* to root@'%' identified by "1234";
mysql> flush privileges;

10、添加防火牆端口

[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
重新載入:
[root@localhost ~]# firewall-cmd --reload
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章