系統版本:
[root@localhost ~]# uname -r
2.6.32-358.el6.i686
[root@localhost ~]# cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m
下載linux generic 32bit的mysql包(http://dev.mysql.com/downloads/mysql/ )。
步驟開始:
1,直接wget下載,或者下載後上傳到服務器端。
2,解壓。
3,將解壓生成的mysql目錄複製到/usr/local/mysql,並在其下新建data目錄。
4,新建用戶mysql和用戶組mysql,並將mysql目錄進行權限修改。
[root@localhost local]# pwd
/usr/local
[root@localhost local]# chown -R mysql:mysql mysql/
[root@localhost mysql]# ll
total 56
drwxr-xr-x. 2 mysql mysql 4096 Jun 26 01:42 bin
-rw-r--r--. 1 mysql mysql 17987 Jun 26 01:42 COPYING
drwxr-xr-x. 5 mysql mysql 4096 Jun 26 04:40 data
drwxr-xr-x. 2 mysql mysql 4096 Jun 26 01:42 docs
drwxr-xr-x. 3 mysql mysql 4096 Jun 26 01:42 include
drwxr-xr-x. 5 mysql mysql 4096 Jun 26 01:43 lib
drwxr-xr-x. 4 mysql mysql 4096 Jun 26 01:42 man
-rw-r--r--. 1 mysql mysql 2478 Jun 26 01:39 README
drwxr-xr-x. 28 mysql mysql 4096 Jun 26 01:42 share
drwxr-xr-x. 2 mysql mysql 4096 Jun 26 01:43 support-files
[root@localhost mysql]#
[root@localhost mysql]# pwd
/usr/local/mysql
5,初始化數據。
[root@localhost mysql]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
[root@localhost mysql]# //以上basedir datadir目錄是屬於默認目錄,若安裝目錄非
//默認/usr/local/mysql,比如目錄爲/usr/local/mysql-5.7.13
//則需要手動指定,並在目錄下./support-files/mysql.server
//文件中指定basedir和datadir的實際目錄。
//端口修改是在./support-files/my-default.cnf文件中。
6,複製配製文件。
[root@localhost mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]#
7,將Mysql的服務腳本放到/etc/init.d/目錄下。
[root@localhost mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]#
8,啓動服務。
[root@localhost mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
[root@localhost mysql]#
9,查看初始密碼,並登錄mysql。
[root@localhost mysql]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2016-06-26 02:48:47
:jiDfmi%5kaK
[root@localhost mysql]# ./bin/mysql -uroot -p
Enter password: (此處輸入上述密碼)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.13
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>
mysql> status (下面會有報錯,提示需要修改密碼後再執行命令)
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
10,修改mysql登錄密碼。
[root@localhost mysql]# ./bin/mysqladmin -uroot -p password
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.
[root@localhost mysql]#
11,使用新密碼即可登錄mysql。
[root@localhost mysql]# ./bin/mysql -uroot -p
Enter password: (新密碼)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server 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 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> select version();
+-----------+
| version() |
+-----------+
| 5.7.13 |
+-----------+
1 row in set (0.01 sec)
mysql>
12,至此mysql安裝完成。
報錯解決:
1,
[root@localhost mysql-5.7.13]# ./bin/mysql_install_db --user=mysql
2016-06-26 02:47:09 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-06-26 02:47:09 [ERROR] The data directory needs to be specified.
解決:需要新建data目錄,指定安裝目錄(在非默認目錄時需要指定,默認路徑:/usr/local/mysql,同時需要指定./support-files/mysql.server中的basedir和datadir爲相應路徑)。
[root@localhost mysql-5.7.13]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.13/ --datadir=/usr/local/mysql-5.7.13/data/
2016-06-26 02:48:47 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-06-26 02:49:19 [WARNING] The bootstrap log isn't empty:
2016-06-26 02:49:19 [WARNING] 2016-06-26T09:48:50.798592Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-06-26T09:48:50.898732Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-06-26T09:48:50.898778Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
以上報錯均因未在mysql.server中指定自定義的路徑。
2,啓動mysql服務不成功。
[root@localhost ~]# /etc/init.d/mysqld start
/etc/init.d/mysqld: line 256: my_print_defaults: command not found
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
解決:原來默認路徑是/usr/local/mysql目錄,這裏存放目錄是/usr/local/mysql-5.7.13。
將mysql-5.7.13改爲mysql再啓動,發現如下錯誤:
ERROR! MySQL server PID file could not be found!
確認當前目錄所有者爲root,改爲mysql:
[root@localhost local]# chown -R mysql:mysql mysql/
[root@localhost local]# /etc/init.d/mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL....... SUCCESS!
3,登錄不成功,是因爲服務沒啓動。
[root@localhost mysql-5.7.13]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2016-06-26 02:48:47
:jiDfmi%5kaK
[root@localhost mysql-5.7.13]# ./bin/mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解決:上面第2個問題解決後,此問題消失(需要將mysqld服務啓動)。
4,修改端口號後,啓動服務報錯:
ERROR! MySQL server PID file could not be found!
Starting MySQL.. ERROR! The server quit without updating PID file(/usr/local/mysql-5.7.13/data/CentOS.pid)
解決:
發現./data目錄下果然沒有CentOS.pid文件。
查看./data/目錄下的報錯日誌Centos.err。
發現如下提示(主要查找 [ERROR]標識的,而[Warning]和[Note]可忽略 ):
variable 'Port = 3308' 無法識別。
在/etc/my.cnf中把Port改爲port(大寫P改爲小寫p),重新啓動,正常。
--文件默認是大寫Port,但還是需要改爲小寫port。
--另外說明查看錯誤信息/日誌的重要性,很多問題可以自己發現解決。
5,數據庫無法登錄問題:
MYSQL提示:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YSE)
解決:
[root@localhost mysql]# bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@localhost mysql]# bin/mysql -u mysql
重置密碼:
mysql>update user set authentication_string=password('your_new_password') where user='root' ;
*特別提醒注意的一點是,新版的mysql數據庫下的user表中已經沒有Password字段了,而是將加密後的用戶密碼存儲於authentication_string字段。否則會提示:
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
6, 提示如下信息:
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解決:
mysql> alter user 'root'@'localhost' identified by 'root' ;
Query OK, 0 rows affected (0.46 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.10 sec)
mysql>
參考:http://www.cnblogs.com/azhw/p/5143232.html