Linux 下安装mysql

Linux 下安装mysql

前前后后装了几次MySQL,但是还是能遇到各种问题,索性就归纳一次,以防以后出现同样的错误。


一、准备工作

下载MySQL,我下载的是mysql-5.7.9-1.el6.x86_64.rpm-bundle.tar,点击下载mysql-5.7.9-1.el6.x86_64.rpm-bundle.tar可以在官网下载其他版本。


二、检查系统是已经否存在MySQL

命令:rpm -qa | grep mysql //检查通过rpm以安装的mysql版本。

[root@tb1 ~]# rpm -qa | grep mysql

mysql-libs-5.1.71.e16.x86_64


三、卸载系统原有的MySQL

【命令】:rpm -e mysql // 普通删除模式(如有依赖无法卸载)
【命令】:rpm -e --nodeps mysql // 强力删除模式(可以忽略依赖)
【命令】:yum -y remove mysql    // yum卸载可以卸载依赖包
mysql-libs-5.1.71.e16.x86_64 有依赖(测试过),所以用rpm -e --nodeps命令。
[root@tb1 ~]# rpm -e --nodeps mysql-libs-5.1.71.e16.x86_64

四、安装自己的MySQL

    上传以下载好的MySQL:mysql-5.7.9-1.el6.x86_64.rpm-bundle.tar,并解压。mysql解压后有很多零散的文件,
选择新建一个目录进行解压,便于好的管理和安装。

1.新建目录
[root@tb1 ~] mkdir -p /usr/local/mysql

2.负责MySQL到新建的目录。
[root@tb1 ~] cp /mysql-5.7.9-1.el6.x86_64.rpm-bundle.tar /usr/local/mysql

3.进入MySQL包目录
[root@tb1 ~] cd /usr/local/mysql
[root@tb1 mysql]# ll
总用量 853572
-rw-r--r--. 1 root root  437022720 7月  23 14:01 mysql-5.7.9-1.el6.x86_64.rpm-bundle.tar

4.解压mysql
[root@tb1 mysql]# tar -vxf mysql-5.7.9-1.el6.x86_64.rpm-bundle.tar
[root@tb1 mysql]# ll
总用量 853572
-rw-r--r--. 1 root root  437022720 7月  23 14:01
mysql-5.7.9-1.el6.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 wheel  24134464 10月 12 2015
mysql-community-client-5.7.9-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 wheel    331912 10月 12 2015
mysql-community-common-5.7.9-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 wheel   3851928 10月 12 2015
mysql-community-devel-5.7.9-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 wheel  38081256 10月 12 2015
mysql-community-embedded-5.7.9-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 wheel 130479844 10月 12 2015
mysql-community-embedded-devel-5.7.9-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 wheel   2224356 10月 12 2015
mysql-community-libs-5.7.9-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 wheel   1720248 10月 12 2015
mysql-community-libs-compat-5.7.9-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 wheel 139636924 10月 12 2015
mysql-community-server-5.7.9-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 wheel  96549460 10月 12 2015
mysql-community-test-5.7.9-1.el6.x86_64.rpm

5.依次执行下面步骤添加mysql所需要的依赖。

安装第一个 mysql-community-common-5.7.9-1.el6.x86_64.rpm,

命令:rpm -ivh mysql-community-common-5.7.9-1.el6.x86_64.rpm

安装第二个 mysql-community-server-5.7.9-1.el6.x86_64.rpm

命令:rpm -ivh mysql-community-server-5.7.9-1.el6.x86_64.rpm

安装第三个 mysql-community-client-5.7.9-1.el6.x86_64.rpm

命令:rpm -ivh mysql-community-client-5.7.9-1.el6.x86_64.rpm

安装第四个 mysql-community-libs-5.7.9-1.el6.x86_64.rpm

命令:rpm -ivh mysql-community-libs-5.7.9-1.el6.x86_64.rpm

安装第五个 mysql-community-server-5.7.9-1.el6.x86_64.rpm

命令:rpm -ivh mysql-community-server-5.7.9-1.el6.x86_64.rpm


发现还有许多需要很多的依赖包。需要从新安装依赖,则需要用到yum安装了。

安装第六个 mysql-community-server-5.7.9-1.el6.x86_64.rpm

命令:yum -install -y mysql-community-server-5.7.9-1.el6.x86_64.rpm



出现上图表示依赖包以加载完毕。


6.初始化mysql

命令:mysqld --initialize 

不会提示和任何消息,但是会在/var/log/目录下生成一个mysqld.log文件,此文件包含着MySQL第一次登录时的初始密码。

查看mysqld.log文件

命令:cat /var/log/mysqld.log

[root@tb1 log]# cat /var/log/mysqld.log

2017-07-23T06:53:34.320711Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-23T06:53:35.675810Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-07-23T06:53:35.983333Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-07-23T06:53:36.046408Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a652ec88-6f73-11e7-ae11-0800270a69b8.
2017-07-23T06:53:36.049362Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-07-23T06:53:36.050127Z 1 [Note] A temporary password is generated for root@localhost: s:..o!tQk9!D

s:..o!tQk9!D就是MySQL初始密码


7.修改权限

[root@tb1 log]#  chown -R  mysql:mysql mysql


8.启动MySQL服务

[root@tb1 log]# /etc/init.d/mysqld start  //启动mysql 服务。
正在启动 mysqld:                                          [确定]

[root@tb1 log]# /etc/init.d/mysqld status //查看mysql状态
mysqld (pid  2084) 正在运行...                                        

[root@tb1 log]# /etc/init.d/mysqld stop   //关闭mysql 服务。
正在启动 mysqld:                                          [确定]


9.登录MySQL

命令: mysql -uroot -p 

[root@tb1 log]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.9 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> 

这里的密码就是刚才谈到的mysqld.log文件里初始化密码。


安装完成


登录问题可以查看下一篇Linux 下第一次使用MySQL遇到几种情况博客。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值