MySQL安裝過程中出現的問題
1>解壓縮MySQL
[[email protected] test]# tar -xvf MySQL-5.6.12-2.linux_glibc2.5.i386.rpm-bundle.tar MySQL-test-5.6.12-2.linux_glibc2.5.i386.rpm MySQL-shared-5.6.12-2.linux_glibc2.5.i386.rpm MySQL-embedded-5.6.12-2.linux_glibc2.5.i386.rpm MySQL-client-5.6.12-2.linux_glibc2.5.i386.rpm MySQL-devel-5.6.12-2.linux_glibc2.5.i386.rpm MySQL-server-5.6.12-2.linux_glibc2.5.i386.rpm MySQL-shared-compat-5.6.12-2.linux_glibc2.5.i386.rpm
2>安裝MySQL
(1) 如果已經安裝了MySQL,會出現以下提示資訊:
[[email protected] test]# rpm -ivh MySQL-server-5.6.12-2.linux_glibc2.5.i386.rpm
Preparing... ########################################### [100%]
package MySQL-server-5.6.12-2.linux_glibc2.5.i386 is already installed
[[email protected] test]# rpm -ivh MySQL-client-5.6.12-2.linux_glibc2.5.i386.rpm
Preparing... ########################################### [100%]
package MySQL-client-5.6.12-2.linux_glibc2.5.i386 is already installed
可以先進行解除安裝MySQL
使用命令rpm –e MySQL-server-5.6.12-2.linux_glibc2.5.i386.rpm –nodeps
rpm –e MySQL-server-5.6.12-2.linux_glibc2.5.i386.rpm --nodeps
(2)如果沒有提示這些資訊,那麼會正常安裝.
[[email protected] test]# rpm -ivh MySQL-server-5.6.12-2.linux_glibc2.5.i386.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
[[email protected] test]# rpm -ivh MySQL-client-5.6.12-2.linux_glibc2.5.i386.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
3>啟動MySQL
(1)首次啟動MySQL伺服器,出現異常資訊的解決辦法
[[email protected] test]# service mysql start
Starting MySQL.......................... ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.pid).
由於mysql啟動的僵死程序,需要將其殺死之後方能啟動
[[email protected] test]# ps -ef | grep mysql
root 1953 1 0 22:18 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid
mysql 2171 1953 0 22:18 ? 00:00:04 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid
root 3282 1 0 22:37 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.pid
mysql 3386 3282 2 22:37 pts/0 00:00:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.err --pid-file=/var/lib/mysql/localhost.pid
root 3482 2681 0 22:38 pts/0 00:00:00 grep mysql
使用kill -9 2171之類殺死
再使用service mysql start或者/etc/init.d/mysql start
[[email protected] test]# service mysql start
Starting MySQL SUCCESS!
4>登入MySQL
[[email protected] test]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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_secret中
cat .mysql_secret
進入mysql之後需要設定密碼,否則不能進行任何操作,如果提示ERROR 1862 (HY000): Your password has expired. To log in you must
change it using a client that supports expired passwords. \
那麼也需要重新設定密碼
MySQL文件中詞條MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS有下面的資訊
查詢SET PASSWORD
為root使用者設定新密碼
set password for ‘root’@’localhost’=password(‘root’)
之後可以進行正常的操作
忘記mysql root密碼的解決方法
一. MySQL密碼的恢復方法之一
如果忘記了MySQL的root密碼,可以用以下方法重新設定:
1. KILL掉系統裡的MySQL程序;
killall -TERM mysqld
2. 用以下命令啟動MySQL,以不檢查許可權的方式啟動;
safe_mysqld --skip-grant-tables &
3. 然後用空密碼方式使用root使用者登入 MySQL;
mysql -u root
4. 修改root使用者的密碼;
mysql> update mysql.user set password=PASSWORD('新密碼') where User='root';
mysql> flush privileges;
mysql> quit
重新啟動MySQL,就可以使用新密碼登入了。
二. MySQL密碼的恢復方法二
有可能你的系統沒有 safe_mysqld 程式(比如我現在用的 ubuntu作業系統, apt-get安裝的mysql) , 下面方法可以恢復
1. 停止mysqld;
/etc/init.d/mysql stop
(您可能有其它的方法,總之停止mysqld的執行就可以了)
2. 用以下命令啟動MySQL,以不檢查許可權的方式啟動;
mysqld --skip-grant-tables &
3. 然後用空密碼方式使用root使用者登入 MySQL;
mysql -u root
4. 修改root使用者的密碼;
mysql> update mysql.user set password=PASSWORD('newpassword') where User='root';
mysql> flush privileges;
mysql> quit
重新啟動MySQL
/etc/init.d/mysql restart
就可以使用新密碼 newpassword 登入了
mysql The server quit without updating PID file異常解決辦法
安裝好mysql後,用
Java程式碼 www.2cto.com
/usr/local/mysql/bin/mysqld_safe &
去啟動mysql,總是處於僵死狀態,後來去suport_files 用mysql.server start 來啟動,
提示mysql The server quit without updating PID file。在網上找了下,原來說是有mysql
啟動的僵死程序。
用ps -ef |grep mysql 發現有
www.2cto.com
Php程式碼
root 4507 1 0 21:40 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe -
-user=mysql
mysql 4793 4507 0 21:40 ? 00:00:03 /usr/local/mysql/bin/mysqld --basedir=
/usr/local/mysql.......
於是kill 4793,再啟動。就正常了
ps:kill root下的程序4507是沒
Mysql報錯的解決'Can't connect to local MySQL server through socket '/tmp/mysql.sock'
[[email protected] mysql]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
[[email protected] mysql]# service mysqld restart 這裡說明mysqld並沒有啟動,
MySQL manager or server PID file could not be found! [FAILED]
Starting MySQL/etc/init.d/mysqld: line 159: kill: (18977) - No such process
[FAILED]
[[email protected] mysql]# cd bin
[[email protected] bin]# ./mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) 這裡就說了不能通過/tmp/mysql.sock連線資料庫。
[[email protected] bin]# cd /tmp 進去檢查,看到有這個檔案,所以看別的原因。
[[email protected] tmp]# ls
gconfd-root mapping-root mysql.sock mysql-test-ports mysql-test-ports.sem scim-panel-socket:0-root VMwareDnD vmware-root vmware.txt
[[email protected] tmp]# cd /usr/local/mysql/
[[email protected] mysql]# pwd
/usr/local/mysql
[[email protected] mysql]# chown -R root:mysql . 忽然想起來了沒有設定許可權呢,開始設定許可權
[[email protected] mysql]# ll
total 36
drwxr-xr-x 2 root mysql 4096 Nov 28 21:51 bin
drwxr-xr-x 3 root mysql 4096 Nov 28 21:50 include
drwxr-xr-x 2 root mysql 4096 Nov 28 21:50 info
drwxr-xr-x 3 root mysql 4096 Nov 28 21:50 lib
drwxr-xr-x 2 root mysql 4096 Nov 28 21:51 libexec
drwxr-xr-x 4 root mysql 4096 Nov 28 21:50 man
drwxr-xr-x 8 root mysql 4096 Nov 28 21:51 mysql-test
drwxr-xr-x 3 root mysql 4096 Nov 28 21:50 share
drwxr-xr-x 5 root mysql 4096 Nov 28 21:50 sql-bench
[[email protected] mysql]# chown -R mysql /var/lib/mysql
[[email protected] mysql]# cp share/mysql/my-huge.cnf /etc/my.cnf
[[email protected] mysql]# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
[[email protected] mysql]# chmod 755 /etc/rc.d/init.d/mysqld
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig --level 345 mysqld on
=======error========
[[email protected] mysql]# mysqladmin -u root password 'uplooking'
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists! 又是上邊一樣的錯誤
[[email protected] mysql]# bin/mysql start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
[[email protected] mysql]# /etc/rc.d/init.d/mysqld status
MySQL is not running, but lock exists [FAILED] 這裡說的是沒有執行著mysql,但是還在鎖定。這時候我看到了下邊那篇文章,重新檢查了一遍許可權,
[[email protected] mysql]# chown -R mysql:mysql /var/lib/mysql 在這裡,我原來設定的時候這個組沒有設定,只寫了chown -R mysql /var/lib/mysql,分組被我忽略掉了,哎,折騰這麼長時間。
[[email protected] mysql]# /etc/rc.d/init.d/mysqld start 從這裡,mysql啟動正常了
Starting MySQL [ OK ]
[[email protected] mysql]# /etc/rc.d/init.d/mysqld stop
Shutting down MySQL [ OK ]
[[email protected] mysql]#
[[email protected] mysql]# mysqladmin -u root password 'uplooking' 這裡是說伺服器沒有啟動
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
[[email protected] mysql]# /etc/rc.d/init.d/mysqld start 啟動伺服器
Starting MySQL [ OK ]
[[email protected] mysql]# mysqladmin -u root password 'uplooking' 新增root密碼
[[email protected] mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[[email protected] mysql]# mysql -u root -p 用root密碼登陸,測試。
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.56-Comsenz-log Source
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> quit
Bye
[[email protected] mysql]# service mysqld restart
Shutting down MySQL [ OK ]
Starting MySQL [ OK ]
[[email protected] mysql]#
====許可權的驗證測試====
[[email protected] mysql]# cd /tmp
[[email protected] tmp]# mkdir test
[[email protected] tmp]# cd test
[[email protected] test]# ls
[[email protected] test]# touch 11
[[email protected] test]# ll
total 0
-rw-r--r-- 1 root root 0 Nov 28 22:37 11
[[email protected] test]# chown -R mysql 11
[[email protected] test]# ll
total 0
-rw-r--r-- 1 mysql root 0 Nov 28 22:37 11
[[email protected] test]#
=========================