mysql 5.7 初始化数据库_MySQL 5.7 新特性之初始化
1. 把二進制安裝包下載放在/opt 目錄下并解壓
2. 創建軟連接, 并添加運行環境
ln -s /usr/local/mysql?/opt/mysql-5.7.18-linux-glibc2.5-x86_64
[root@M1 local]# ll | grep mysql
lrwxrwxrwx 1 root root 39 Jul 26 12:00 mysql -> /opt/mysql-5.7.18-linux-glibc2.5-x86_64
export PATH=$PATH:$HOME/bin:/usr/local/mysql/bin 加到環境變量
3. 創建mysql 用戶
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
4. 創建目錄結構和賦權
mkdir /data/mysql/3306/ -p
cd data
mkdir {data,logs,tmp}
chown mysql:mysql -R /data
5.生產cnf 配置文件
推薦使用葉老師的在線cnf 文件生產工具 http://imysql.com/my-cnf-wizard.html
6. 初始化
[root@M1 bin]# ./mysqld --initialize --datadir=/data/mysql/3306/data --user=mysql --basedir=/usr/local/mysql/
2017-07-26T08:24:03.273745Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-26T08:24:04.102255Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-07-26T08:24:04.243150Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-07-26T08:24:04.314543Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c9102823-71db-11e7-ba5c-005056b643b3.
2017-07-26T08:24:04.321167Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-07-26T08:24:04.322012Z 1 [Note] A temporary password is generated for root@localhost:?2hpi85k*T-t=
我們可以看到root@localhost 被賦予隨機生成的一個密碼,這與以往的mysql版本不一樣, 另外mysql_install_db 這個工具也不再被推薦了,mysql_install_db?is deprecated. Please consider switching to?mysqld --initialize
另外,在初始化時如果加上–initial-insecure,則會創建空密碼的 root@localhost 賬號,否則會創建帶密碼的 root@localhost 賬號,密碼直接寫在 log-error 日志文件中(在5.6版本中是放在 ~/.mysql_secret 文件里,更加隱蔽,不熟悉的話可能會無所適從)
7.啟動數據庫
8. 使用剛剛生成的密碼就可以正常登錄了
[root@M1 bin]# mysql -uroot -p -S /data/mysql3306.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-log
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>
9. 想要更加美觀? 也是可以的
在~/.bash_profile 加上export MYSQL_PS1="\\u@\\h:\\p [\\d]>"
或者可以在[mysql] 添加
[mysql]
prompt=\\u@\\h:\\p [\\d]>
root@localhost:mysql3306.sock [(none)]>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
root@localhost:mysql3306.sock [(none)]>use sys
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
root@localhost:mysql3306.sock [sys]>
==========最后總結======
快速初始化腳本如下:
1. 把壓縮文件放在/opt 下面
2. my.cnf 文件的內容需要和以下文件目錄匹配
#!/bin/sh
cd /opt
tar zxvf mysql*.tar.gz
ln -s /usr/local/mysql /opt/mysql*linux-glibc2.5-x86_64
cat >> /etc/profile <
export MYSQL_PS1="\\u@\\h:\\p [\\d]>"
export PATH=\$PATH:/usr/local/mysql/bin
EOF
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
mkdir /data/mysql/3306/ -p
cd /data/mysql/3306
mkdir {data,logs,tmp}
chown mysql:mysql -R /data
總結
以上是生活随笔為你收集整理的mysql 5.7 初始化数据库_MySQL 5.7 新特性之初始化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: yum mysql_yum安装mysql
- 下一篇: elasticsearch 根据条件去除