Linux下Mysql安裝

silent發表於2014-03-12

1、下載安裝包

     首先檢視Linux版本:

[root@localhost ~]# lsb_release -a
LSB Version:    :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:    RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 6.3 (Santiago)
Release:    6.3
Codename:    Santiago

  結果顯示系統為64位Redhat6.3 ,去Mysql官網(http://dev.mysql.com/downloads/mysql#downloads)下載相應的版本。

wget http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-devel-5.5.36-1.el6.x86_64.rpm
wget http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-client-5.5.36-1.el6.x86_64.rpm
wget http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-server-5.5.36-1.el6.x86_64.rpm

2、安裝Mysql服務和客戶端

rpm -ivh MySQL-server-5.5.36-1.el6.x86_64.rpm
[root@localhost mysql]# rpm -ivh MySQL-server-5.5.36-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at http://bugs.mysql.com/

[root@localhost mysql]# rpm -ivh MySQL-client-5.5.36-1.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]

可能遇到的問題

1>如果出現類似:

file /usr/share/mysql/charsets/hebrew.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64
    file /usr/share/mysql/charsets/hp8.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64
    file /usr/share/mysql/charsets/keybcs2.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64
    file /usr/share/mysql/charsets/koi8r.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64
    file /usr/share/mysql/charsets/koi8u.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64
    file /usr/share/mysql/charsets/latin1.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64

說明有包衝突,這時候要移除衝突的包,使用命令:

yum -y remove mysql-libs-5.1.61*

2>如果移除時出現:

Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
Existing lock /var/run/yum.pid: another copy is running as pid 14110.

說明YUM正在更新,使用命令:

rm -f    /var/run/yum.pid

3、服務啟動、停止、重新啟動

[root@localhost usr]# service mysql start

[root@localhost usr]# service mysql stop

[root@localhost usr]# service mysql restart

4、修改root密碼

[root@localhost bin]# mysqladmin -u root -p'root' password 'rockontrol'

5、常見問題

登入出現 Access denied for user 'root'@'localhost' (using password:YES)。解決步驟如下:

a:以root使用者登入系統

b:看一下Mysql服務的狀態 如果啟動則殺掉程式 命令如下

[root@localhost ~]# /etc/init.d/mysql status
 ERROR! MySQL is running but PID file could not be found
[root@localhost ~]# ps aux|grep mysql
root      1468  0.0  0.0 115216  1680 ?        S    6月16   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid
mysql     1638  0.0  2.7 1040276 455956 ?      Sl   6月16   0:29 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid
root     17015  0.0  0.0 112660   976 pts/0    S+   08:42   0:00 grep --color=auto mysql
[root@localhost ~]# kill 1468
[root@localhost ~]# kill 1638
[root@localhost ~]# kill 17015

c:啟動特權命令:mysqld_safe --skip-grant-tables &

d:在重新開啟一個連線以普通使用者命令進去   這時候就不需要在輸入密碼了

[root@localhost ~]# mysql -u root -p
Enter password: 

直接回車就可以進去了   然後修改user表的密碼就可以了

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> select host,user,password from user;
+-----------------------+------+-------------------------------------------+
| host                  | user | password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *68A463BD53874E39A4D68117C03FB1A777EC9DA9 |
| localhost.localdomain | root | *68A463BD53874E39A4D68117C03FB1A777EC9DA9 |
| 127.0.0.1             | root | *68A463BD53874E39A4D68117C03FB1A777EC9DA9 |
| ::1                   | root | *68A463BD53874E39A4D68117C03FB1A777EC9DA9 |
+-----------------------+------+-------------------------------------------+
4 rows in set (0.00 sec)

mysql> update user set host='%' where host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update user set password='';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

這樣就清空所有的密碼了
e:這時候可以退出特權模式 重新啟動Mysql服務  然後修改一下密碼就可以了

SET PASSWORD=PASSWORD('123456');

 

相關文章