centos安装mysql

由于服务器没有连外网,所以使用光盘安装

[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         : http://www.mysql.com
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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29819001/viewspace-1320931/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值