当前位置:网站首页>Linux(CentOS7)安裝MySQL-5.7版本
Linux(CentOS7)安裝MySQL-5.7版本
2022-06-12 01:44:00 【我先測了】
1. 從官網下載mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz官網:http://dev.mysql.com/downloads/mysql/
# wget -chttp://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
2. 創建mysql的用戶組/用戶, data目錄及其用戶目錄
# groupadd mysql
# useradd -r -g mysql mysql
# mkdir -p /data/mysqldb
3. 解壓安裝包並將解壓包裏的內容拷貝到mysql的安裝目錄/home/mysql
# tar -xzvf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
# cd mysql-5.7.14-linux-glibc2.5-x86_64
# mv * /usr/local/mysql
# mkdir -p /usr/local/mysql 創建mysql安裝目錄,可以把解壓的mysql-5.7.14-linux-glibc2.5-x86_64文件夾下的文件移到目錄下
4. 初始化mysql數據庫cd /usr/local/mysql
\# ./bin/mysql\_install\_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb
2015-11-1002:09:17 \[WARNING\] mysql\_install\_db is deprecated. Please consider switching to mysqld --initialize
2015-11-1002:09:23 \[WARNING\] The bootstrap logisn't empty:
2015-11-1002:09:23 \[WARNING\] 2015-11-10T10:09:18.114182Z 0 \[Warning\] --bootstrap is deprecated. Please consider using --initialize instead
2015-11-10T10:09:18.129343Z 0 \[Warning\] Changed limits: max\_open\_files: 1024 (requested 5000)
2015-11-10T10:09:18.129408Z 0 \[Warning\] Changed limits: table\_open\_cache: 431 (requested 2000)
p.s. : mysql5.7新特性:由上面可以看出,mysql_install_db 已經不再推薦使用了,建議改成mysqld --initialize 完成實例初始化。
\# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb --initialize
改用 mysqld --initialize 後,如果 datadir 指向的目標目錄下已經有數據文件, 會出現如下提示:
\# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb --initialize
2016-04-08T01:46:53.153530Z 0 \[Warning\] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit\_defaults\_for\_timestamp server option (see documentation for more details).
2016-04-08T01:46:53.155856Z 0 \[ERROR\] --initialize specified but the data directory has files in it. Aborting.
2016-04-08T01:46:53.155879Z 0 \[ERROR\] Aborting
由上可知, 我們需要清空mysql的data目錄, 執行清空命令如下:
\# cd /data/mysqldb# rm -fr \*
然後重新執行初始化命令如下:
[[email protected] /] cd /usr/local/mysql
[[email protected] mysql ] ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb --initialize
[[email protected] ]2016-04-08T01:47:57.556677Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-04-08T01:47:59.945537Z 0 [Warning] InnoDB: New logfiles created, LSN=45790
2016-04-08T01:48:00.333528Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-04-08T01:48:00.434908Z 0 [Warning] No existing UUID has been found, so we assume that this is thefirsttime that this server has been started. Generating anew UUID: ece26421-fd2b-11e5-a1e3-00163e001e5c.2016-04-08T01:48:00.440125Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2016-04-08T01:48:00.440904Z 1 [Note] A temporary password is generated for [email protected]: **mjT,#x_5sW
牢記上面的隨機密碼, 如上**mjT,#x_5sW, 下面我們修改密碼時需要用到。
5. 檢測下是否能啟動mysql服務
# cd /usr/local/mysql# ./support-files/mysql.server start
Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid). #沒有經過cmake編輯過的,初始化數據庫會失敗;
解决辦法:vim support-files/mysql.server 指定datadir=/data/mysqldb basedir=/usr/local/mysql
Starting MySQL… SUCCESS!
若改用了/usr/local/mysql為mysql的安裝目錄basedir, 則在啟動服務時會出現如下錯誤:
[[email protected] mysql] #./support-files/mysql.server start
[[email protected] ]./support-files/mysql.server: line 276: cd: /usr/local/mysql: No such fileor directory
[[email protected] ] Starting MySQL ERROR! Couldn’t find MySQL server (/usr/local/mysql/bin/mysqld_safe)
由上面可知mysql的tar.gz安裝包的默認安裝目錄為/usr/local/mysql, 這時候我們需要修改/support-files/mysql.server文件的basedir和datadir目錄路徑為我們環境所在的mysql的basedir和datadir路徑, 如下:
- [[email protected] ]
- # vim support-files/mysql.server
- --------------------------
- …
- basedir=/usr/local/mysql
- datadir=/data/mysqldb
- …
- --------------------------
- # ./support-files/mysql.server start
- Starting MySQL… SUCCESS!
6. 創建軟鏈接
\# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
7. 創建配置文件
將默認生成的my.cnf備份
\# mv /etc/my.cnf /etc/my.cnf.bak
進入mysql的安裝目錄支持文件目錄
\# cd /usr/local/mysql/support-files
拷貝配置文件模板為新的mysql配置文件,
\# cp my-default.cnf /etc/my.cnf
可按需修改新的配置文件選項, 不修改配置選項, mysql則按默認配置參數運行.
如下是我修改配置文件/etc/my.cnf, 設置編碼為utf8以防亂碼
\# vim /etc/my.cnf\[mysqld\]basedir = /usr/local/mysqldatadir = /data/mysqldbcharacter\_set\_server=utf8init\_connect='SET NAMES utf8'\[client\]default-character-set=utf8
8. 配置mysql服務開機自動啟動
拷貝啟動文件到/etc/init.d/下並重命令為mysqld
\# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
增加執行權限
\# chmod 755 /etc/init.d/mysqld
檢查自啟動項列錶中沒有mysqld這個,如果沒有就添加mysqld:
\# chkconfig --list mysqld# chkconfig --add mysqld
設置MySQL在345等級自動啟動
\# chkconfig --level 345 mysqld on
或用這個命令設置開機啟動:
\# chkconfig mysqld on
9. mysql服務的啟動/重啟/停止
啟動mysql服務
\# service mysqld start
重啟mysql服務
\# service mysqld restart
停止mysql服務
\# service mysqld stop
可以先將文件最底部這句删除或注釋掉:sql\_mode=NO\_ENGINE\_SUBSTITUTION,STRICT\_TRANS\_TABLES
10. 初始化mysql用戶root的密碼
先將mysql服務停止
\# service mysqld stop
進入mysql安裝目錄, 執行:
# cd /usr/local/mysql
# ./bin/mysqld_safe --skip-grant-tables --skip-networking&
[1] 6225
[[email protected] mysql]# 151110 02:46:08 mysqld_safe Logging to ‘/data/mysqldb/localhost.localdomain.err’.151110 02:46:08 mysqld_safe Starting mysqld daemon with databases from /data/mysqldb
另外打開一個終端(p.s. 如果是ssh連接登錄的, 另外創建一個ssh連接即可), 執行操作如下:
# mysql -u root mysql#運行此句時,需要先執行上一句:./bin/mysqld_safe
Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -A********************************************************************Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> use mysql;Database changed
mysql> UPDATE user SET password=PASSWORD(‘root’) WHERE user=‘root’;ERROR 1054 (42S22): Unknown column ‘password’ in ‘field list’
mysql> update user set authentication_string = PASSWORD(‘root’) where user = ‘root’;
Query OK, 1 row affected, 1 warning (0.02 sec)Rows matched: 1 Changed: 1 Warnings: 1
#MySQL5.7新特性,Users錶中沒有password字段了,authentication_string 就是password
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \s--------------mysql Ver 14.14 Distrib 5.7.9, for linux-glibc2.5 (x86_64) using EditLine wrapperConnection id: 2Current database: mysqlCurrent user: [email protected]: Not in useCurrent pager: stdoutUsing outfile: ''Using delimiter: ;Server version: 5.7.9 MySQL Community Server (GPL)Protocol version: 10Connection: Localhost via UNIX socketServer characterset: utf8Db characterset: utf8Client characterset: utf8Conn. characterset: utf8UNIX socket: /tmp/mysql.sockUptime: 4 min 47 secThreads: 1 Questions: 43 Slow queries: 0 Opens: 127 Flush tables: 1 Open tables: 122 Queries per second avg: 0.149--------------
mysql> exit;Bye
到此, 設置完mysql用戶root的密碼且確保mysql編碼集是utf8, 注意上面,新版本的mysql.user錶裏的密碼字段是authentication\_string
快捷鍵ctrl + c停止# ./bin/mysqld\_safe ...命令, 重新啟動mysql服務, 用新密碼連接mysql:
# service mysqld startStarting MySQL SUCCESS!
[[email protected] bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.9************************************************************************Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql > exit;Bye
咦?又要我改密碼, 我們通過mysqladmin來修改密碼, 先輸入原密碼是上面步驟修改的新密碼root, 再設置新密碼!!!
# cd /usr/local/mysql
# ./bin/mysqladmin -u root -p password
#這個password是參數,不是要設置成root密碼的值Enter password: New password:
Confirm new password:
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.7.9 MySQL Community Server (GPL)Copyright 2000, 2015, Oracle and/or its affiliates. All rights reserved.******************************************************************************Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql>
或直接:
# ./bin/mysqladmin -uroot -p’g!#l4:6+rMnT’ password ‘root’
mysqladmin: [Warning] Using a password on the command line interface can be insecure.Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
其中,g!#l4:6+rMnT就是我們在使用mysqld --initialize時牢記下的隨機密碼
11. mysql遠程授權
格式如下:
mysql> grant all \[privileges\] on db\_name.table\_name to 'username'@'host' identified by 'yourpassword';
示例如下:
mysql> `grant` all privileges on \*.\* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.04 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
或用
mysql> grant all on \*.\* to 'root'@'%' identified by 'root';
到此, 完成了mysql的安裝 及配置!!!
注:最後windows遠程訪問linux-mysql連接失敗,沒有開放端口3306:解决:iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
已驗證安裝MySQL5.7不需要cmake.
边栏推荐
- LeetCode LCP 07. 传递信息
- 2022年金属非金属矿山(小型露天采石场)安全管理人员考试模拟100题及模拟考试
- JSON conversion: entity classes and jsonobject are converted to each other, and list and jsonarray are converted to each other (fastjson version)
- php开发09 文章模块的删除和文章分类编写
- In depth description of Weibull distribution (2) meaning of parameters and formulas
- Lua function
- Interviewer: do you understand redis' shared object pool?
- Redis startup and shutdown commands
- [project training] wechat official account to obtain user openid
- Comprehensive quality of teaching resources in the second half of 2019 - subjective questions
猜你喜欢

pip运行报错:Fatal error in launcher: Unable to create process using

Four schemes for redis to implement message queue

螺旋矩阵(技巧)

PyGame alien invasion

马尔可夫网络 与 条件随机场

感知机从0到1

The road of global evolution of vivo global mall -- multilingual solution

Tiobe - programming language ranking in June 2022

Spiral matrix (skill)

Common assertions for JMeter interface testing
随机推荐
MP3 to Wav to Midi
PCA from 0 to 1
2022年金属非金属矿山(小型露天采石场)安全管理人员考试模拟100题及模拟考试
通过搜索广告附加信息让广告更具相关性
Google 搜索广告系列设置前有哪些准备工作?
Manually tear the linked list (insert, delete, sort) and pointer operation
Dataset how to use dataset gracefully. After reading this article, you can fully understand the dataset in c7n/choerodon/ toothfish UI
“還是學一門技術更保險!”杭州校區小哥哥轉行軟件測試,喜提10K+雙休!
php安全开发 12博客系统的 系统模块信息的修改
Pyinstaller packaging Exe (detailed tutorial)
为什么我们要使用谷歌搜索广告?
自适应搜索广告有哪些优势?
Design practice of rongyun Im on electron platform
How to buy children's serious illness insurance, what to pay attention to and how to choose products
Jvm: thread context classloader
感知机从0到1
如何定位关键词使得广告精准投放。
2022年重氮化工艺考试题库模拟考试平台操作
Interviewer: do you understand redis' shared object pool?
广泛匹配修饰符符号已经被弃用,请勿使用