安装MySQL 5.6
记录安装mysql 5.6的全过程
下载安装包(尝试过使用mysql的yum源去安装--如果你的网络够好的话。。。)
注:我的系统是Centos 7.2的 如下,根据自己的需求去下载
1 2 | CentOS Linux release 7.2.1511 (Core) 3.10.0-327.el7.x86_64 |
下载下面的rpm 捆绑包,下载这一个
Centos服务器上安装MySQL依赖包
1 | yum -y install perl perl-devel net-tools |
将下载好的捆绑包上传到服务器
解压
1 2 3 4 5 6 7 | [root@WCY mysql56]# ls MySQL-5.6.41-1.el7.x86_64.rpm-bundle.tar [root@WCY mysql56]# tar xf MySQL-5.6.41-1.el7.x86_64.rpm-bundle.tar [root@WCY mysql56]# ls MySQL-5.6.41-1.el7.x86_64.rpm-bundle.tar MySQL-embedded-5.6.41-1.el7.x86_64.rpm MySQL-shared-compat-5.6.41-1.el7.x86_64.rpm MySQL-client-5.6.41-1.el7.x86_64.rpm MySQL-server-5.6.41-1.el7.x86_64.rpm MySQL-test-5.6.41-1.el7.x86_64.rpm MySQL-devel-5.6.41-1.el7.x86_64.rpm MySQL-shared-5.6.41-1.el7.x86_64.rpm |
创建MySQL用户与组
1 | useradd -M -s /sbin/nologin mysql |
安装
1 2 3 4 5 6 7 | rpm -ivh MySQL-client-5.6.41-1.el7.x86_64.rpm rpm -ivh MySQL-shared-5.6.41-1.el7.x86_64.rpm rpm -ivh MySQL-devel-5.6.41-1.el7.x86_64.rpm rpm -ivh MySQL-shared-compat-5.6.41-1.el7.x86_64.rpm rpm -ivh MySQL-embedded-5.6.41-1.el7.x86_64.rpm rpm -ivh MySQL-test-5.6.41-1.el7.x86_64.rpm rpm -ivh MySQL-server-5.6.41-1.el7.x86_64.rpm |
创建mysql配置文件my.cnf
1 | [root@WCY ~] # cp /usr/share/mysql/my-default.cnf /etc/my.cnf |
初始化MySQL
1 2 3 | [root@WCY ~] # /usr/bin/mysql_install_db FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db : Data::Dumper |
报错解决:
1 | [root@WCY ~] # yum install -y perl-Module-Install.noarch |
解决完报错别忘了 再执行初始化
启动MySQL
1 2 | [root@WCY ~] # systemctl start mysql Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details. |
启动报错,查看下
1 2 3 4 5 6 7 8 9 | [root@WCY ~] # journalctl -xe 9月 20 21:25:03 WCY. local yum[18450]: Installed: perl-HTTP-Daemon-6.01-7.el7.noarch 9月 20 21:25:03 WCY. local yum[18450]: Installed: perl-HTTP-Negotiate-6.01-5.el7.noarch ································· 9月 20 21:31:18 WCY. local mysql[18635]: Starting MySQL. ERROR! The server quit without updating PID file ( /var/lib/mysql/WCY . local .pid). 9月 20 21:31:18 WCY. local systemd[1]: mysql.service: control process exited, code=exited status=1 9月 20 21:31:18 WCY. local systemd[1]: Failed to start LSB: start and stop MySQL. |
可以看到
1 | ERROR! The server quit without updating PID file ( /var/lib/mysql/WCY . local .pid). |
先设置下目录权限
1 | [root@WCY ~] # chown -R mysql:mysql /var/lib/mysql/ |
再启动
1 2 3 | [root@WCY ~] # systemctl start mysql.service [root@WCY ~] # netstat -anpt | grep mysql tcp6 0 0 :::3306 :::* LISTEN 18891 /mysqld |
已启动
设置MySQL密码
1 | [root@WCY ~] # /usr/bin/mysqladmin -u root password 'mima' |
‘mima’替换为你要设置的密码
如果你的系统版本是CentOS6.x的
安装完MySQL5.6.x后密码为自动生成的保存在本用户目录下隐藏文件.mysql_secret
1 2 | [root@Check1 ~] # cat .mysql_secret # The random password set for the root user at Sat Oct 20 11:37:06 2018 (local time): c5SoTcrXmMYFBMsU |
更改root密码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | [root@Check1 ~] # mysql -uroot -pc5SoTcrXmMYFBMsU 使用生成的密码登录数据库测试一下 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.6.41 Copyright (c) 2000, 2018, 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@Check1 ~] # mysqladmin -uroot -p password '123123' 设置新的密码为123123 回车后输入上面生成的密码 Enter password: Warning: Using a password on the command line interface can be insecure. [root@Check1 ~] # mysql -uroot -p123123 用新密码登录 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.6.41 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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> |
安装结束,优化后续再说。。。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步