星火燎原

千日修以返初心 万日炼以达极致

导航

Linux环境下卸载、安装及配置MySQL5.1

Linux环境下卸载原有MySQL5.1数据库,并重新安装MySQL数据库的示例记录。

一、卸载MySQL

查看主机中是否安装了MySQL数据库:

[root@RD-viPORTAL-1 ~]# rpm -qa|grep mysql
mysql-5.1.73-5.el6_6.x86_64
mysql-devel-5.1.73-5.el6_6.x86_64
mysql-libs-5.1.73-5.el6_6.x86_64

然后通过rpm -e命令进行软件包的卸载;

[root@RD-viPORTAL-1 ~]# rpm -e mysql-5.1.73-5.el6_6.x86_64
error: Failed dependencies:
    mysql = 5.1.73-5.el6_6 is needed by (installed) mysql-devel-5.1.73-5.el6_6.x86_64

发现软件包有依赖关系,百度发现可以使用“--nodeps”参数进行卸载。

[root@RD-viPORTAL-1 ~]# rpm -e mysql-5.1.73-5.el6_6.x86_64 --nodeps
[root@RD-viPORTAL-1 ~]# rpm -e mysql-devel-5.1.73-5.el6_6.x86_64 --nodeps
[root@RD-viPORTAL-1 ~]# rpm -e mysql-libs-5.1.73-5.el6_6.x86_64 --nodeps

再次查询MySQL的软件包,发现已经没有相关的rpm包了。

[root@RD-viPORTAL-1 ~]# rpm -qa|grep mysql
[root@RD-viPORTAL-1 ~]#

 

二、安装MySQL

安装MySQL一般需要如下rpm包。

[root@RD-viPORTAL-1 mysql]# ll
总用量 11788
-rw-r--r-- 1 root root  915088 2月  15 05:27 mysql-5.1.73-5.el6_6.x86_64.rpm
-rw-r--r-- 1 root root  131900 2月  15 05:27 mysql-devel-5.1.73-5.el6_6.x86_64.rpm
-rw-r--r-- 1 root root 1282760 2月  15 05:27 mysql-libs-5.1.73-5.el6_6.x86_64.rpm
-rw-r--r-- 1 root root 9033560 2月  15 05:27 mysql-server-5.1.73-5.el6_6.x86_64.rpm
-rw-r--r-- 1 root root  136464 2月  15 05:32 perl-DBD-MySQL-4.013-3.el6.x86_64.rpm

安装顺序:

perl-DBD-MySQL-4.013-3.el6.x86_64.rpm
mysql-libs-5.1.73-5.el6_6.x86_64.rpm
mysql-5.1.73-5.el6_6.x86_64.rpm
mysql-server-5.1.73-5.el6_6.x86_64.rpm
mysql-devel-5.1.73-5.el6_6.x86_64.rpm

 

安装过程:

使用“rpm -ivh”命令安装rpm包。

[root@RD-viPORTAL-1 mysql]# rpm -ivh mysql-libs-5.1.73-5.el6_6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:mysql-libs             ########################################### [100%]

[root@RD-viPORTAL-1 mysql]# rpm -ivh mysql-5.1.73-5.el6_6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:mysql                  ########################################### [100%]
[root@RD-viPORTAL-1 mysql]# 
[root@RD-viPORTAL-1 mysql]# rpm -ivh mysql-server-5.1.73-5.el6_6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:mysql-server           ########################################### [100%]
[root@RD-viPORTAL-1 mysql]# 
[root@RD-viPORTAL-1 mysql]# rpm -ivh mysql-devel-5.1.73-5.el6_6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:mysql-devel            ########################################### [100%]

使用service命令查看MySQL安装状态:

[root@RD-viPORTAL-1 mysql]# service mysqld status
mysqld 已停

使用service命令启动MySQL并初始化:

[root@RD-viPORTAL-1 mysql]# service mysqld start
初始化 MySQL 数据库: 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 RD-viPORTAL-1 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!

                                                           [确定]
正在启动 mysqld:                                          [确定]
[root@RD-viPORTAL-1 mysql]#

查询3306端口确认是否正常启动:

[root@RD-viPORTAL-1 mysql]# netstat -an|grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      
unix  2      [ ACC ]     STREAM     LISTENING     19314  /tmp/orbit-gdm/linc-c5a-0-4d33062e40154
unix  3      [ ]         STREAM     CONNECTED     19323  /tmp/orbit-gdm/linc-c5a-0-4d33062e40154
unix  3      [ ]         STREAM     CONNECTED     19320  /tmp/orbit-gdm/linc-c5a-0-4d33062e40154

MySQL默认配置路径:

[root@RD-viPORTAL-1 mysql]# cd /var/lib/mysql/
[root@RD-viPORTAL-1 mysql]# ll
总用量 20488
-rw-rw---- 1 mysql mysql 10485760 2月  15 05:52 ibdata1
-rw-rw---- 1 mysql mysql  5242880 2月  15 05:52 ib_logfile0
-rw-rw---- 1 mysql mysql  5242880 2月  15 05:52 ib_logfile1
drwx------ 2 mysql mysql     4096 2月  15 05:52 mysql
srwxrwxrwx 1 mysql mysql        0 2月  15 05:52 mysql.sock
drwx------ 2 mysql mysql     4096 2月  15 05:52 test

 

三、配置MySQL

设置root用户密码

默认情况下MySQL是不需要登录密码的,为安全起见,设置MySQL密码。

[root@RD-viPORTAL-1 mysql]# mysqladmin -u root password "passw0rd"

此时直接登录显示访问拒绝:

[root@RD-viPORTAL-1 mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

使用如下命令登录MySQL:

[root@RD-viPORTAL-1 mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.1.73 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> select * from user;
ERROR 1046 (3D000): No database selected
mysql> exit
Bye

授权root用户可以远程访问:

[root@RD-viPORTAL-1 mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.1.73 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> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@RD-viPORTAL-1 mysql]#

posted on 2017-02-17 16:25  xusweeter  阅读(282)  评论(0编辑  收藏  举报