Linux下安装MySQL

        之前在配置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

        卸载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

        要想完全清理掉所有与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

        然后按照下面的命令安装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%]

        成功安装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 ]

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

mysql –u root –p

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

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

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

[root@hadoop ~]# chkconfig --levels 235 mysql on
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

skyWalker_ONLY

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值