mysql是免费开源的数据库产品,我们在centos mysql安装时报No package mysql-server available错误是因为我们本地yum仓库中没有可用的mysql-server rpm包,因此在yum安装之前先在本地备好rpm软件包。
[root@VM_230_32_centos ~]# yum install mysql-server Loaded plugins: fastestmirror, ovl base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 http://ftp.iitm.ac.in/centos/7.3.1611/updates/x86_64/repodata/repomd.xml : [Errno 14] curl#52 - "Empty reply from server" Trying other mirror. updates | 3.4 kB 00:00:00 ........ No package mysql-server available. Error: Nothing to do
下面我们对centos6/7系统分开来解决此问题,以安装的是mysql5.7为例
在Centos 7上使用
[root@VM_230_32_centos ~]# rpm -ivh https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm Retrieving https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm warning: /var/tmp/rpm-tmp.7OOdD1: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql57-community-release-el7-11 ################################# [100%] [root@eb2476e8763c /]#
Centos 6上安装mysql rpm包
[root@VM_230_32_centos ~]# rpm -ivh https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm Retrieving https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm warning: /var/tmp/rpm-tmp.TWlyW7: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql57-community-release-el6-11 ################################# [100%]
rpm软件包安装好之后,我们就可以使用yum install mysql-server命令来安装mysql了。
[root@VM_230_32_centos ~]# yum install mysql-server Loaded plugins: fastestmirror, ovl base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql57-community | 2.5 kB 00:00:00 updates | 3.4 kB 00:00:00 mysql-connectors-community/x86_64/primary_db | 16 kB 00:00:01 Loading mirror speeds from cached hostfile ...... Installed: mysql-community-server.x86_64 0:5.7.19-1.el7 Verify the installed packages using "rpm" command
安装好mysql之后,就可以启动mysql服务器了,centos6/7系统启动mysql服务的方式也不是一样的。
Centos 7系统启动mysql命令
systemctl start mysql
Centos 6启动mysql命令
service mysqld start
验证mysql是否启动成功命令,使用netstat命令
[root@VM_230_32_centos ~]# netstat -nap |grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4571/mysqld
最后需要查看mysql5.7的初始化密码(如果是mysql5.6的话默认密码应该为空,不需要此命令查询)
# grep 'temporary password' /var/log/mysqld.log
输出类似如下的随机密码(红色部分)
2017-11-08T16:24:46.311098Z 1 [Note] A temporary password is generated for root@localhost: MtPqF0/oN5zoSfdff
然后输入mysql -uroot -p命令登录mysql服务器,并修改mysql初始化密码。
[root@VM_219_180_centos ~]# mysql -uroot -p //输入初始化密码登录之后,重新设置mysql密码 mysql> set password for root@localhost = password('123456');