Home > Database > Mysql Tutorial > body text

Linux下安装MySQL

WBOY
Release: 2016-06-07 15:19:59
Original
1108 people have browsed it

之前在配置MySQL做为Hive的Metastore时,曾安装过MySQL,但可惜的是并没有记录整个过程。现在忽然发现MySQL不能使用了,试过网上的很多方法都不行,所以决定将MySQL卸载掉,重新安装,并记录整个过程以备再次重装MySQL。首先使用下面的命令查询已经安装的MyS

        之前在配置MySQL做为Hive的Metastore时,曾安装过MySQL,但可惜的是并没有记录整个过程。现在忽然发现MySQL不能使用了,试过网上的很多方法都不行,所以决定将MySQL卸载掉,重新安装,并记录整个过程以备再次重装MySQL。首先使用下面的命令查询已经安装的MySQL:

[root@hadoop local]# rpm -qa | grep -i mysql
MySQL-client-5.6.21-1.rhel5.x86_64
MySQL-server-5.6.21-1.el6.x86_64
Copy after login

        卸载MySQL使用下面的命令,由于其它应用可能依赖MySQL,所以使用了--nodeps强制卸载MySQL:

[root@hadoop local]# rpm -e --nodeps MySQL-server-5.6.21-1.el6.x86_64
[root@hadoop local]# rpm -e --nodeps MySQL-client-5.6.21-1.rhel5.x86_64
Copy after login

        要想完全清理掉所有与MySQL相关的文件,可以使用find命令进行查找,然后删除。在完成MySQL的卸载后,下面进行安装,通常情况下只需要安装server和client即可:

[root@hadoop hadoop]# ls My*
MySQL-client-5.6.21-1.rhel5.x86_64.rpm  MySQL-server-5.6.21-1.el6.x86_64.rpm
Copy after login

        然后按照下面的命令安装server和client:

[root@hadoop hadoop]# rpm -ivh MySQL-server-5.6.21-1.el6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server         ########################################### [100%]

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

New default config file was created as /usr/my.cnf and will be used by default by the server when you start it.You may edit this file to change server settings

[root@hadoop hadoop]# rpm -ivh MySQL-client-5.6.21-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client         ########################################### [100%]
Copy after login

        成功安装MySQL后,根据输出信息可知默认为root用户生成了随机密码并保存在/root/.mysql_secret文件中,可以在登录MySQL后进行修改。同时移除了之前很多版本中存在的匿名用户(匿名用户指user表中user字段为空的用户即为匿名用户,该用户的密码也为空)。其它信息还有在生产环境中如何移除测试数据库等。默认将MySQL安装在/var/lib/mysql中,在此次安装中不会对默认设置做任何修改。

        可以使用/etc/init.d/mysql脚本启动、停止、重启MySQL数据库,该脚本的具体用法如下:

[root@hadoop ~]# /etc/init.d/mysql
Usage: mysql  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]
Copy after login

        现在修改root的初始密码,首先要使用该初始密码登录到MySQL中,具体命令为:

mysql –u root –p
Copy after login

        在登录MySQL后,使用下面的命令为root用户设置新密码:

mysql> set password = password('root');
Query OK, 0 rows affected (0.01 sec)
Copy after login

        剩下的最后一步就是将MySQL设置为随系统启动而启动,虽然实现这一点的方式有很多种,但推荐按照官方文档的方式:

[root@hadoop ~]# chkconfig --levels 235 mysql on
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!