程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> MySQL安裝過程中出現的問題

MySQL安裝過程中出現的問題

編輯:MySQL綜合教程

MySQL安裝過程中出現的問題   1>解壓縮MySQL  

[html] 
[root@localhost 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    [html]  (1) 如果已經安裝了MySQL,會出現以下提示信息:     
[root@localhost 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  
  
[root@localhost 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  
[html] 
rpm –e MySQL-server-5.6.12-2.linux_glibc2.5.i386.rpm --nodeps  

 

  (2)如果沒有提示這些信息,那麼會正常安裝.  
[html] 
[root@localhost test]# rpm -ivh MySQL-server-5.6.12-2.linux_glibc2.5.i386.rpm  
  
Preparing...                ########################################### [100%]  
  
1:MySQL-server           ########################################### [100%]  
  
[root@localhost test]# rpm -ivh MySQL-client-5.6.12-2.linux_glibc2.5.i386.rpm   
  
Preparing...                ########################################### [100%]  
  
1:MySQL-client           ########################################### [100%]  

 

    3>啟動MySQL   (1)首次啟動MySQL服務器,出現異常信息的解決辦法  
[html] 
[root@localhost test]# service mysql start  
  
Starting MySQL.......................... ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.pid).  

 

  由於mysql啟動的僵死進程,需要將其殺死之後方能啟動  
[html] 
[root@localhost 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  
[html] 
[root@localhost test]# service mysql start  
  
Starting MySQL SUCCESS!  

 

    4>登錄MySQL  
[html] 
[root@localhost 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中  
[html] 
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用戶設置新密碼  
[html] 
set password for ‘root’@’localhost’=password(‘root’)  

 

之後可以進行正常的操作   忘記mysql root密碼的解決方法   一. MySQL密碼的恢復方法之一   如果忘記了MySQL的root密碼,可以用以下方法重新設置:  
1. KILL掉系統裡的MySQL進程;

[html] 
killall -TERM mysqld  
2. 用以下命令啟動MySQL,以不檢查權限的方式啟動;
[html] 
safe_mysqld --skip-grant-tables &  

3. 然後用空密碼方式使用root用戶登錄 MySQL;
[html] 
mysql -u root  
4. 修改root用戶的密碼;
[html] 
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;   
[html] 
/etc/init.d/mysql stop  

 

  (您可能有其它的方法,總之停止mysqld的運行就可以了)   2. 用以下命令啟動MySQL,以不檢查權限的方式啟動;   
[html] 
mysqld --skip-grant-tables &  

 

  3. 然後用空密碼方式使用root用戶登錄 MySQL;   mysql -u root   4. 修改root用戶的密碼;  
[html] 
mysql> update mysql.user set password=PASSWORD('newpassword') where User='root';  
  
mysql> flush privileges;  
  
mysql> quit  

 

  重新啟動MySQL  
[html] 
/etc/init.d/mysql restart  

 

  就可以使用新密碼 newpassword 登錄了   mysql The server quit without updating PID file異常解決辦法       安裝好mysql後,用   Java代碼    /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   發現有  
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'  
[root@localhost mysql]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)

[root@localhost 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]

[root@localhost mysql]# cd bin

[root@localhost bin]# ./mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)        這裡就說了不能通過/tmp/mysql.sock連接數據庫。

[root@localhost bin]# cd /tmp    進去檢查,看到有這個文件,所以看別的原因。

[root@localhost 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

[root@localhost tmp]# cd /usr/local/mysql/

[root@localhost mysql]# pwd

/usr/local/mysql

[root@localhost mysql]# chown -R root:mysql .      忽然想起來了沒有設置權限呢,開始設置權限

[root@localhost 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

[root@localhost mysql]# chown -R mysql /var/lib/mysql

[root@localhost mysql]# cp share/mysql/my-huge.cnf /etc/my.cnf

[root@localhost mysql]# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld

[root@localhost mysql]# chmod 755 /etc/rc.d/init.d/mysqld

[root@localhost mysql]# chkconfig --add mysqld

[root@localhost mysql]# chkconfig --level 345 mysqld on

=======error========

[root@localhost 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!  又是上邊一樣的錯誤

[root@localhost mysql]# bin/mysql start

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)

[root@localhost mysql]# /etc/rc.d/init.d/mysqld status

MySQL is not running, but lock exists                      [FAILED] 這裡說的是沒有運行著mysql,但是還在鎖定。這時候我看到了下邊那篇文章,重新檢查了一遍權限,

[root@localhost mysql]# chown -R mysql:mysql /var/lib/mysql 在這裡,我原來設置的時候這個組沒有設置,只寫了chown -R mysql /var/lib/mysql,分組被我忽略掉了,哎,折騰這麼長時間。

[root@localhost mysql]# /etc/rc.d/init.d/mysqld start 從這裡,mysql啟動正常了

Starting MySQL                                             [  OK  ]

[root@localhost mysql]# /etc/rc.d/init.d/mysqld stop

Shutting down MySQL                                        [  OK  ]

[root@localhost mysql]#

[root@localhost 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!

[root@localhost mysql]# /etc/rc.d/init.d/mysqld start 啟動服務器

Starting MySQL                                             [  OK  ]

[root@localhost mysql]# mysqladmin -u root password 'uplooking' 添加root密碼

[root@localhost mysql]# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@localhost 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

[root@localhost mysql]# service mysqld restart

Shutting down MySQL                                        [  OK  ]

Starting MySQL                                             [  OK  ]

[root@localhost mysql]#

====權限的驗證測試====

[root@localhost mysql]# cd /tmp

[root@localhost tmp]# mkdir test

[root@localhost tmp]# cd test

[root@localhost test]# ls

[root@localhost test]# touch 11

[root@localhost test]# ll

total 0

-rw-r--r-- 1 root root 0 Nov 28 22:37 11

[root@localhost test]# chown -R mysql 11

[root@localhost test]# ll

total 0

-rw-r--r-- 1 mysql root 0 Nov 28 22:37 11

[root@localhost test]#

=========================

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved