Mysql 5.7 Centos7 環境安裝

在以下網址下載安裝Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package(mysql57-community-release-el7-8.noarch.rpm)

http://dev.mysql.com/downloads/repo/yum/


可以直接執行

yum install http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

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
Is this ok [y/d/N]: y


使用yum安裝mysql server

yum install mysql-community-server
Dependencies Resolved

=========================================================================================================================================================================================================
 Package                                                     Arch                                   Version                                      Repository                                         Size
=========================================================================================================================================================================================================
Installing:
 mysql-community-libs                                        x86_64                                 5.7.14-1.el7                                 mysql57-community                                 2.1 M
     replacing  mariadb-libs.x86_64 1:5.5.47-1.el7_2
 mysql-community-libs-compat                                 x86_64                                 5.7.14-1.el7                                 mysql57-community                                 2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.47-1.el7_2
 mysql-community-server                                      x86_64                                 5.7.14-1.el7                                 mysql57-community                                 152 M
Installing for dependencies:
 mysql-community-client                                      x86_64                                 5.7.14-1.el7                                 mysql57-community                                  24 M
 mysql-community-common                                      x86_64                                 5.7.14-1.el7                                 mysql57-community                                 271 k

Transaction Summary
=========================================================================================================================================================================================================
Install  3 Packages (+2 Dependent packages)

Total download size: 180 M
Is this ok [y/d/N]: y


mysql 5.6 以上版本安裝時會有一個隨機密碼,在mysql日誌裏查詢

cat /var/log/mysqld.log |grep "A temporary password"
[Note] A temporary password is generated for root@localhost: Thm34de873

Thm34de873就是此次mysql 5.7安裝的隨機密碼.

開啓mysqlserver服務,嘗試登陸成功。

systemctl start mysqld
mysql -u root -p 
Enter password: Thm34de873
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.14

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


mysql 5.7 執行操作前要求必須更改初始密碼,新密碼寫在單引號''裏。

mysql> SELECT 1;ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

mysql> SET PASSWORD = PASSWORD('new_password');
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT 1;+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

密碼有強度要求,如要關閉,在/etc/my.cnf中添加validate-password=OFF


默認root用戶只能在localhost登陸,更改爲可在任意地方登陸,方便但不安全。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

mysql> select user, host from user ;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| mysql.sys | localhost |
| root      | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)


mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select user, host from user ;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| root      | %         |
| mysql.sys | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)

mysql> flush privileges;  
Query OK, 0 rows affected (0.00 sec)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章