CentOS安裝MySQL

君落塵發表於2014-11-05
由於伺服器沒有連外網,所以使用光碟安裝

[root@oracledb ~]# cd /etc/yum.repos.d/
[root@oracledb yum.repos.d]# ls
CentOS-Base.repo  CentOS-Base.repo.bak  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo
[root@oracledb yum.repos.d]#cat  CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=file:///media
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
掛載光碟
[root@oracledb yum.repos.d]# mount /dev/sr0 /media
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@oracledb yum.repos.d]# yum list | grep mysql
apr-util-mysql.x86_64                  1.3.9-3.el6_0.1                  base    
bacula-director-mysql.x86_64           5.0.0-12.el6                     base    
bacula-storage-mysql.x86_64            5.0.0-12.el6                     base    
dovecot-mysql.x86_64                   1:2.0.9-7.el6                    base    
freeradius-mysql.x86_64                2.1.12-4.el6_3                   base    
libdbi-dbd-mysql.x86_64                0.8.3-5.1.el6                    base    
mod_auth_mysql.x86_64                  1:3.0.0-11.el6_0.1               base    
mysql.x86_64                           5.1.71-1.el6                     base    
mysql-bench.x86_64                     5.1.71-1.el6                     base    
mysql-connector-java.noarch            1:5.1.17-6.el6                   base    
mysql-connector-odbc.x86_64            5.1.5r1144-7.el6                 base    
mysql-devel.i686                       5.1.71-1.el6                     base    
mysql-devel.x86_64                     5.1.71-1.el6                     base    
mysql-embedded.i686                    5.1.71-1.el6                     base    
mysql-embedded.x86_64                  5.1.71-1.el6                     base    
mysql-embedded-devel.i686              5.1.71-1.el6                     base    
mysql-embedded-devel.x86_64            5.1.71-1.el6                     base    
mysql-libs.i686                        5.1.71-1.el6                     base    
mysql-libs.x86_64                      5.1.71-1.el6                     base    
mysql-server.x86_64                    5.1.71-1.el6                     base    
mysql-test.x86_64                      5.1.71-1.el6                     base    
php-mysql.x86_64                       5.3.3-26.el6                     base    
qt-mysql.i686                          1:4.6.2-26.el6_4                 base    
qt-mysql.x86_64                        1:4.6.2-26.el6_4                 base    
rsyslog-mysql.x86_64                   5.8.10-8.el6                     base    

安裝
[root@oracledb yum.repos.d]#  yum install -y mysql-server mysql mysql-deve
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
No package mysql-deve available.
Resolving Dependencies
--&gt Running transaction check
---&gt Package mysql.x86_64 0:5.1.71-1.el6 will be installed
--&gt Processing Dependency: mysql-libs = 5.1.71-1.el6 for package: mysql-5.1.71-1.el6.x86_64
--&gt Processing Dependency: libmysqlclient_r.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.71-1.el6.x86_64
--&gt Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.71-1.el6.x86_64
--&gt Processing Dependency: libmysqlclient_r.so.16()(64bit) for package: mysql-5.1.71-1.el6.x86_64
--&gt Processing Dependency: libmysqlclient.so.16()(64bit) for package: mysql-5.1.71-1.el6.x86_64
---&gt Package mysql-server.x86_64 0:5.1.71-1.el6 will be installed
--&gt Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.71-1.el6.x86_64
--&gt Running transaction check
---&gt Package mysql-libs.x86_64 0:5.1.71-1.el6 will be installed
---&gt Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
--&gt Finished Dependency Resolution


Dependencies Resolved


====================================================================================================================================
 Package                             Arch                        Version                            Repository                 Size
====================================================================================================================================
Installing:
 mysql                               x86_64                      5.1.71-1.el6                       base                      893 k
 mysql-server                        x86_64                      5.1.71-1.el6                       base                      8.6 M
Installing for dependencies:
 mysql-libs                          x86_64                      5.1.71-1.el6                       base                      1.2 M
 perl-DBD-MySQL                      x86_64                      4.013-3.el6                        base                      134 k


Transaction Summary
====================================================================================================================================
Install       4 Package(s)


Total download size: 11 M
Installed size: 31 M
Downloading Packages:
------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                               2.1 MB/s |  11 MB     00:05     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
** Found 7 pre-existing rpmdb problem(s), 'yum check' output follows:
akonadi-1.2.1-2.el6.x86_64 has missing requires of mysql-server
akonadi-1.2.1-2.el6.x86_64 has missing requires of qt4-mysql
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of mysql-libs
redland-1.0.7-11.el6.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
redland-1.0.7-11.el6.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
  Installing : mysql-libs-5.1.71-1.el6.x86_64                                                                                   1/4 
  Installing : perl-DBD-MySQL-4.013-3.el6.x86_64                                                                                2/4 
  Installing : mysql-5.1.71-1.el6.x86_64                                                                                        3/4 
  Installing : mysql-server-5.1.71-1.el6.x86_64                                                                                 4/4 
  Verifying  : perl-DBD-MySQL-4.013-3.el6.x86_64                                                                                1/4 
  Verifying  : mysql-server-5.1.71-1.el6.x86_64                                                                                 2/4 
  Verifying  : mysql-5.1.71-1.el6.x86_64                                                                                        3/4 
  Verifying  : mysql-libs-5.1.71-1.el6.x86_64                                                                                   4/4 


Installed:
  mysql.x86_64 0:5.1.71-1.el6                                   mysql-server.x86_64 0:5.1.71-1.el6                                  


Dependency Installed:
  mysql-libs.x86_64 0:5.1.71-1.el6                                perl-DBD-MySQL.x86_64 0:4.013-3.el6                               


Complete!
安裝成功,檢視版本

[root@oracledb yum.repos.d]# rpm -qi mysql-server
Name        : mysql-server                 Relocations: (not relocatable)
Version     : 5.1.71                            Vendor: CentOS
Release     : 1.el6                         Build Date: Sat 23 Nov 2013 07:53:06 AM CST
Install Date: Wed 05 Nov 2014 08:56:34 AM CST      Build Host: c6b8.bsys.dev.centos.org
Group       : Applications/Databases        Source RPM: mysql-5.1.71-1.el6.src.rpm
Size        : 25876424                         License: GPLv2 with exceptions
Signature   : RSA/SHA1, Mon 25 Nov 2013 03:32:44 AM CST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <
URL         :
Summary     : The MySQL server and related files
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MySQL server and some accompanying files and directories.
檢視目錄

[root@oracledb yum.repos.d]# find / -name mysql
/var/lib/mysql
/usr/lib64/perl5/auto/DBD/mysql
/usr/lib64/perl5/DBD/mysql
/usr/lib64/mysql
/usr/bin/mysql
/usr/share/mysql

[root@oracledb yum.repos.d]# rpm -qa|grep -i mysql
mysql-libs-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64
mysql-5.1.71-1.el6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64

啟動服務
[root@oracledb yum.repos.d]# service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK


To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


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 oracledb 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.


You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &


You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl


Please report any problems with the /usr/bin/mysqlbug script!


[  OK  ]
Starting mysqld:  [  OK  ]


設定開機啟動
[root@oracledb yum.repos.d]#  chkconfig --list | grep mysqld
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root@oracledb yum.repos.d]# chkconfig mysqld on
[root@oracledb yum.repos.d]#  chkconfig --list | grep mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off


設定引數
mysql資料庫安裝完以後只會有一個root管理員賬號,但是此時的root賬號還並沒有為其設定密碼,在第一次啟動mysql服務時,
會進行資料庫的一些初始化工作,在輸出的一大串資訊中,我們看到有這樣一行資訊 :
/usr/bin/mysqladmin -u root password 'new-password'  // 為root賬號設定密碼
所以我們可以透過 該命令來給我們的root賬號設定密碼(注意:這個root賬號是mysql的root賬號,非Linux的root賬號)

[root@oracledb yum.repos.d]# mysqladmin -u root password 'root'   // 透過該命令給root賬號設定密碼為 root
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
[root@oracledb yum.repos.d]# /usr/bin/mysqladmin -u root password 'root'
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
[root@oracledb yum.repos.d]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


注意:如果無法進入MySQL介面常見情況有2種


一種屬於:服務未啟動

一種屬於:密碼錯誤



出現密碼錯誤,解決方法如下:
[root@oracledb etc]#  /etc/init.d/mysqld stop
Stopping mysqld:  [  OK  ]
[root@oracledb etc]# mysqld_safe --skip-grant-tables &
[1] 6751
[root@oracledb etc]# 141105 09:18:56 mysqld_safe Logging to '/var/log/mysqld.log'.
141105 09:18:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
/usr/bin/mysql -uroot -p             //輸入/usr/bin/mysql -uroot -p
Enter password:                      //直接回車
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.71 Source distribution


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> 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 password=password("root") where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql>  flush privileges;
Query OK, 0 rows affected (0.00 sec)


mysql>  quit
Bye
[root@oracledb etc]# mysql -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.71 Source distribution


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> quit
Bye

啟動服務

[root@oracledb etc]# service mysqld restart
141105 09:25:12 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:  [  OK  ]
Starting mysqld:  [  OK  ]
[1]+  Done                    mysqld_safe --skip-grant-tables
[root@oracledb etc]# /usr/bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.71 Source distribution


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> quit
Bye
[root@oracledb etc]# umount /media

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29819001/viewspace-1320931/,如需轉載,請註明出處,否則將追究法律責任。

相關文章