mysql5.7:安裝教程
阿新 • • 發佈:2018-01-12
hat 數據庫表 ide sql nologin uid data use 切換
從mysql官網下載安裝包:/mysql-5.7.20-linuxglibc2.12-x86_64.tar.gz
#切換目錄 cd /usr/local #解壓下載的安裝包 tar -zxvf /software/mysql/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz #重命名 mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql #建立數據存儲目錄 mkdir data #建立用戶組 groupadd mysql #建立用戶,並禁止用戶登錄 useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql #改變文件歸屬 chown -R mysql.mysql /usr/local/mysql/ #初始化系統數據庫,記住不能用./bin/mysql_install_db,已經過期了 ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
初始化後,會打印日誌,如下 ,註意看最後輸出,紅色標記部分,這個就是root的臨時密碼。
2018-01-12T05:08:12.048923Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use--explicit_defaults_for_timestamp server option (see doc umentation for more details). 2018-01-12T05:08:12.228535Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-01-12T05:08:12.251370Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-01-12T05:08:12.305856Z 0 [Warning] No existing UUID has been found, so we a ssume that this is the first timethat this server has been started. Generating a new UUID: 968b7130-f756-11e7-8704-000c29009e57. 2018-01-12T05:08:12.306388Z 0 [Warning] Gtid table is not ready to be used. Tabl e ‘mysql.gtid_executed‘ cannot be opened. 2018-01-12T05:08:12.307188Z 1 [Note] A temporary password is generated for root@localhost: LwchxXdoO5*8
配置數據庫:
vi /etc/my.cnf
my.cnf內容:
[mysqld] #目錄設置 basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=3306 #服務ID socket=/tmp/mysql.sock #數據庫表名大小寫不敏感 lower_case_table_names=1 #設置字符集,防止中文亂碼 init_connect=‘SET collation_connection = utf8_general_ci‘ init_connect=‘SET NAMES utf8‘ character-set-server=utf8 collation-server=utf8_general_ci skip-character-set-client-handshake [client] default-character-set=utf8 [mysql] default-character-set=utf8
安裝成服務:
cp -a ./support-files/mysql.server /etc/init.d/mysqld
啟動服務
service mysqld start
登錄到mysql
./bin/mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.20 Copyright (c) 2000, 2017, 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> grant all privileges on *.* to root@"%" identified by "2018dlj123!@#0112" with grant option; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
一開始想做授權,結果發現報錯,原因是必須要修改初始密碼。
修改初始密碼:
mysql> ALTER USER USER() IDENTIFIED BY ‘test123456‘;
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> grant all privileges on *.* to root@"%" identified by "test123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
至此安裝完畢!
mysql5.7:安裝教程