64位Linux下安装mysql-5.7.13-linux-glibc2.5-x86_64 || 转载:http://www.cnblogs.com/gaojupeng/p/5727069.html
?由于公司臨時讓將Oracle的數據移植到mysql上面,所以讓我在公司服務器上面安裝一下mysql。下面就是我的安裝過程以及一些錯誤解決思路。其實對于不同版本安裝大體都有差不多。
1. 從官網下載 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
經測試, 本文還適用于如下版本:?
mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz?
mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
官網:?http://dev.mysql.com/downloads/mysql/
2.檢查你所用的Linux下有沒有安裝過mysql,沒有卸載干凈
| 12 | #rpm -qa|grep -i mysqlmysql-5.7.13-linux-glibc2.5-x86_64 |
*可見已經安裝了庫文件,應該先卸載,不然會出現覆蓋錯誤。注意卸:載時使用了--nodeps選項,忽略了依賴關系:
| 1 | #rpm -e mysql-5.7.13-linux-glibc2.5-x86_64?--nodeps |
當然你的也可能不止這一個文件,也可能有多個,那么你就依次 ?rpm -e xx --nodeps 卸載,卸載完了再檢查一下,若確定刪除干凈后,在經行下面步驟。
3. 創建mysql的用戶組/用戶, data目錄及其用戶目錄
? ?在這步之前一定要先確保你所建的用戶以及用戶組沒有存在,要不然在后面的過程中會報錯,刪除時候要先刪除用戶在刪除用戶組名。
| 123456 | # userdel mysql?????????????????????????????????????????? # 刪除用戶# groupdel mysql????????????????????????????????????????? # 刪除用戶組名# mkdir /home/mysql?????????????????????????????????????? # 在home文件夾下創建文件夾mysql# mkdir /home/mysql/data????????????????????????????????? # 在mysql文件夾下創建文件夾data??# groupadd mysql????????????????????????????????????????? # 創建一個名為mysql的用戶組???????# useradd -g mysql -d /home/mysql mysql?????????????????? # 在用戶組下創建用戶 |
4、解壓安裝包并將解壓包里的內容拷貝到mysql的安裝目錄/home/mysql
| 123 | # tar -xzvf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz????????????? # 解壓文件# cd mysql-5.7.13-linux-glibc2.5-x86_64??????????????????????????? # 進入# mv * /home/mysql??????????????????????????????????????????????? # 移動到之前我創建的mysql文件夾下。 |
5、初始化mysql數據庫(如果執行錯誤,繼續看博文下面內容)
| 12345678 | # cd /home/mysql???????????????????????????????????????? # 進入安裝目錄# ./bin/mysql_install_db??--user=mysql --basedir=/home/mysql --datadir=/home/mysql/data[WARNING] mysql_install_db?is?deprecated. Please consider switching?to?mysqld?--initialize 2015-11-10 02:09:23[WARNING] The bootstrap log isn't empty: 2015-11-10 02: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) |
| 12345 | # ./bin/mysqld?--user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize# ./mysqld?--user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize[Warning]?TIMESTAMP?with?implicit?DEFAULT?value?is?deprecated. Please use?--explicit_defaults_for_timestamp server option (see documentation for more details).[ERROR]?--initialize specified but the data directory has files in it. Aborting. 2016-04-08T01:46:53.155879Z 0[ERROR] Aborting |
| 123456789 | # cd /home/mysql/data??????????????????????? # 進入安裝目錄下的data目錄# rm -fr *?????????????????????????????????? # 清空數據# cd /home/mysql??????# ./bin/mysqld?--user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initialize[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 log files 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?the?first?time?that this server has been started. Generating a new 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?root@localhost: **mjT,#x_5sW |
6、檢測下是否能啟動mysql服務(如果執行錯誤,繼續看博文下面內容)
| 123 | # cd /home/mysql# ./support-files/mysql.server startStarting MySQL.. OK! |
| 123 | # ./support-files/mysql.server start./support-files/mysql.server: line 276: cd: /usr/local/mysql:?No?such file?or?directoryStarting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe) |
| 123456789 | # vim support-files/mysql.server--------------------------...basedir=/home/mysqldatadir=/home/mysql/data...--------------------------# ./support-files/mysql.server startstart Starting MySQL.. OK! |
7、創建軟鏈接
| 1 | # ln -s /home/mysql/bin/mysql /usr/bin/mysql |
8、創建配置文件
下面的前3步操作過程中,可能會出錯,如果有錯就跳過,因為不同電腦的環境不一樣,1、將默認生成的my.cnf備份| 1 | # mv /etc/my.cnf /etc/my.cnf.bak |
| 1 | # cd /home/mysql/support-files |
| 1 | # cp my-default.cnf /etc/my.cnf |
| 12345678910111213 | # vim /etc/my.cnf----------------------------------------------------------------------?[mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. basedir = /home/mysql datadir = /home/mysql/data port = 3306 skip-grant-tables character_set_server=utf8 init_connect='SET NAMES utf8' #設置最大連接數的控制 max_connections=500 # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M? sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES? [client] default-character-set=utf8 |
9、配置mysql服務開機自動啟動
| 12345 | # cp /home/mysql/support-files/mysql.server /etc/init.d/mysqld????? # 拷貝啟動文件到/etc/init.d/下并重命令為mysqld# chmod 755 /etc/init.d/mysqld????????????????????????????????????? # 增加執行權限# chkconfig?--list mysqld?????????????????????????????????????????? # 檢查自啟動項列表中沒有mysqld這個,# chkconfig?--add mysqld??????????????????????????????????????????? # 如果沒有就添加mysqld:# chkconfig mysqld?on???????????????????????????????????????????????# 用這個命令設置開機啟動: |
這樣就是電腦環境的問題了,你就直接把
?
10、mysql服務的啟動/重啟/停止
| 123 | # service mysqld start?????????????????????????????????????????????? # 啟動服務# service mysqld restart???????????????????????????????????????????? # 重啟服務# service mysqld stop??????????????????????????????????????????????? # 停止服務 |
11、初始化mysql用戶root的密碼
| 12345678910111213141516171819202122232425262728293031 | # cd /home/mysql[root@oracle mysql]# 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.15 MySQL Community Server (GPL) 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> 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> update user set authentication_string = PASSWORD('123456') where user = 'root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 ?Changed: 1 ?Warnings: 1 mysql> \s--------------mysql Ver 14.14 Distrib 5.7.13,?for?linux-glibc2.5 (x86_64) using EditLine wrapperConnection?id:? 3Current?database:?? mysqlCurrent?user:?? root@localhostSSL:????Not?in?useCurrent?pager:? stdoutUsing outfile:??''Using delimiter:??? ;Server version: 5.7.13 MySQL Community Server (GPL)Protocol version:?? 10Connection: Localhost via UNIX socketServer characterset:??? utf8Db characterset:??? utf8Client characterset:??? utf8Conn. characterset: utf8UNIX socket:??? /tmp/mysql.sockUptime: 1?hour?29?min?17 sec?Threads: 1 Questions: 50 Slow queries: 0 Opens: 136 Flush tables: 1?Open?tables: 129 Queries per?second?avg: 0.009-------------- |
?修改完成root的密碼之后,將my.cnf中的skip-grant-tables注釋掉
如果這一步完成不了的話,也就是修改不了密碼的話,你也可以直接下面的方式先登錄
但是如果不修改密碼,不進每次登陸麻煩而且在執行一些操作會報一下錯誤
| 1 | You must reset your?password?using?ALTER?USER?statement before executing this statement??? # 意思就是你必須重置你的密碼在執行這個execute操作前 |
這里教大家用另外一種方式修改密碼,這個是在已經登陸進去的情況下依次執行。
| 123456789 | mysql>?SET?PASSWORD?=?PASSWORD('123456');???????????? #?PASSWORD()里面的123456 是我設置的新密碼,你也可以設置成你的密碼Query OK, 0?rows?affected, 1 warning (0.00 sec)Rows?matched: 2 Changed: 0 Warnings: 1mysql>?ALTER?USER?'root'@'localhost'?PASSWORD?EXPIRE NEVER;Query OK, 0?rows?affected, 1 warning (0.00 sec)Rows?matched: 2 Changed: 0 Warnings: 1mysql> flush?privileges;Query OK, 0?rows?affected, 1 warning (0.00 sec)Rows?matched: 2 Changed: 0 Warnings: 1 |
12. mysql遠程授權
| 123456789101112131415161718 | [root@testfornss ~]# mysql -u root -pEnter?password:Welcome?to?the MySQL monitor. Commands?end?with?;?or?\g.Your MySQL?connection?id?is?4Server version: 5.7.13 MySQL Community Server (GPL)?Copyright (c) 2000, 2016, Oracle?and/or?its affiliates.?All?rights reserved.?Oracle?is?a registered trademark?of?Oracle Corporation?and/or?itsaffiliates. Other names may be trademarks?of?their respectiveowners.?Type?'help;'?or?'\h'?for?help. Type?'\c'?to?clear the?current?input statement.?mysql>?grant?all?privileges?on?*.*?to?'root'@'%'?identified?by?'123456';Query OK, 0?rows?affected, 1 warning (0.00 sec)?mysql> |
或者:
| 1 | grant?all?on?*.*?to?'root'@'%'?identified?by?'123456'; |
如果不設置遠程連接,用mysql數據庫連接工具可是連接不上的哦!!!
13.用數據庫連接工具來測試你剛剛的安裝是不是成功了
首先要知道,遠程連接的Linux系統的ip,確保本機已經能夠ping通的情況下再連接。
?
到這里說明你的mysql安裝成功了,是不是感覺特別簡單啊!!!!
總結
以上是生活随笔為你收集整理的64位Linux下安装mysql-5.7.13-linux-glibc2.5-x86_64 || 转载:http://www.cnblogs.com/gaojupeng/p/5727069.html的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做启动盘没电脑怎么办 如何制作启动盘没有
- 下一篇: 03款尼桑蓝鸟2.0加什么型号汽油