一、浩語
時(shí)間,不一定能證明許多東西,但一定會(huì)看透許多東西。越來越覺得,照顧好自己,不給別人添麻煩,是成長(zhǎng)重要的一步。
二、背景
最近離職交接,在折騰disconf所以就需要安裝mysql,因此就引出了安裝問題,記載一下。
三、安裝
先下載包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gzhttps://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

Paste_Image.png
[mbr@localhost bin]$ ./mysql_install_db --user=mbr --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2017-03-22 14:06:12 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-03-22 14:06:12 [ERROR] The data directory '/usr/local/mysql/data' already exist and is not empty.
[mbr@localhost bin]$ ./bin/mysqld --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize
清空data目錄

hah
[mbr@localhost bin]$ ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2017-03-22T06:10:27.796422Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-03-22T06:10:27.796508Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-03-22T06:10:27.796741Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-03-22T06:10:27.799052Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2017-03-22T06:10:27.799081Z 0 [ERROR] Aborting
使用mysql的用戶

Paste_Image.png
[mbr@localhost bin]$ ./mysqld --user=mbr --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2017-03-22T06:10:04.037209Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-03-22T06:10:04.037282Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-03-22T06:10:04.037435Z 0 [Warning] Ignoring user change to 'mbr' because the user was set to 'mysql' earlier on the command line
2017-03-22T06:10:04.037452Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-03-22T06:10:04.039674Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2017-03-22T06:10:04.039704Z 0 [ERROR] Aborting

Paste_Image.png
[mbr@localhost bin]$ ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2017-03-22T06:13:51.307390Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-03-22T06:13:51.307479Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-03-22T06:13:51.307697Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-03-22T06:13:51.310657Z 0 [Warning] One can only use the --user switch if running as root
2017-03-22T06:14:32.306149Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-03-22T06:14:33.132151Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-03-22T06:14:33.275111Z 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: d11d2492-0ec6-11e7-a271-005056be25e7.
2017-03-22T06:14:33.294768Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-03-22T06:14:33.295656Z 1 [Note] A temporary password is generated for root@localhost: lHsaS#S&.2(s
[mbr@localhost bin]$ ../support-files/mysql.server start
Starting MySQL./usr/local/mysql/bin/mysqld_safe: line 586: /var/lib/mysql/mysqld_safe.pid: 沒有那個(gè)文件或目錄
awk: (FILENAME=- FNR=1) 警告: 向標(biāo)準(zhǔn)輸出寫時(shí)發(fā)生錯(cuò)誤 (斷開的管道)
/usr/local/mysql/bin/mysqld_safe: line 139: /var/log/mysqld.log: 權(quán)限不夠
2017-03-22T07:10:08.030812Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
/usr/local/mysql/bin/mysqld_safe: line 139: /var/log/mysqld.log: 權(quán)限不夠
The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).[失敗]
解決方式:
cp /usr/local/mysql/support-files/my-default.cnf /usr/local/mysql/support-files/my.cnf
cp /usr/local/mysql/support-files/my.cnf /etc/
將這個(gè)復(fù)制到/etc/目錄下就行,啟動(dòng)結(jié)果如下

Paste_Image.png

Paste_Image.png
授權(quán)出現(xiàn)問題
You must reset your password using ALTER USER statement before executing this statement.
解決如下:

grant_Image.png
編輯
vim /etc/my.cnf
在[mysqld]下加入skip-grant-tablesshan用來跳過密碼
[mysqld]
skip-grant-tablesshan
重啟mysql
/usr/local/mysql/support-files/mysql.server stop
/usr/local/mysql/support-files/mysql.server start
mysql -uroot -p
###進(jìn)入后
user mysql;
update user set authentication_string=PASSWORD("123456") where user='root' and host='localhost'
上面圖片中g(shù)rant_image的圖片中,由于授權(quán)的提示,所以才又
set PASSWORD = PASSWORD('123456');
每次執(zhí)行了授權(quán)操作后都需要flush privileges刷新下。
我的安裝借鑒了<a >這篇文章</a>
只是在修改不了密碼的時(shí)候我使用跳過密碼的方式來解決,因?yàn)槲恼吕锩娴姆绞竭€是解決不了我登錄不上的問題。
配置啟動(dòng)
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld ###增加執(zhí)行權(quán)限
chkconfig --list mysqld ###檢查啟動(dòng)列表是否已經(jīng)有了mysqld
chkconfig --add mysqld ###添加進(jìn)去
chkconfig mysqld on ###設(shè)置開機(jī)啟動(dòng)

Paste_Image.png
然后就可以使用如下命令進(jìn)行啟動(dòng)停止等操作
service mysqld start
service mysqld restart
service mysqld stop
然后創(chuàng)建軟連接,這樣就可以直接在命令行里面使用mysql的命令比如如下圖片中的登錄mysql -uroot -p
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

Paste_Image.png
其實(shí)這里創(chuàng)建軟連接是一種方式,其實(shí)也可以配置全局變量的方式來.我自己的mac電腦上市這樣配置的。