centos7安装Mysql5.6
Posted java路人甲
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7安装Mysql5.6相关的知识,希望对你有一定的参考价值。
一. 卸载
先卸载centos7自带的mariadb数据库(MariaDB数据库管理系统是mysql的一个分支),如果不卸载掉他的话,那么我们安装的mysql数据库是运行不起来的!
rpm -qa |grep mariadb
rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64 (替换为服务器自带的数据库)
注:如果报错了,那么主要是因为没有加 --nodeps 导致的依赖错误
rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64或者 rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64 --nodeps
二.下载rpm包
下载源文件
wget http://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
(这个版本是在https://dev.mysql.com/downloads/repo/yum/找到)
rpm -ivh mysql-community-release-el6-5.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*" 查看是否有源文件
当这样时,说明已经下好了
三.安装Mysql
输入: yum -y install mysql-community-server 用yum方式安装mysql(一路yes)
四.安装成功后,将其加入开机启动
输入: systemctl enable mysqld
五.启动mysql
输入: systemctl start mysqld
六.配置mysql
输入: mysql_secure_installationTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
进行配置:
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we\'ll need the current
password for the root user. If you\'ve just installed MySQL, and
you haven\'t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y [设置root用户密码]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y [删除匿名用户]
... Success!
Normally, root should only be allowed to connect from \'localhost\'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y [禁止root远程登录]
... Success!
By default, MySQL comes with a database named \'test\' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y [删除test数据库]
- Dropping test database...
ERROR 1008 (HY000) at line 1: Can\'t drop database \'test\'; database doesn\'t exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y [刷新权限]
... Success!
All done! If you\'ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
七:进入 mysql
mysql -uroot -p
八.开启远程访问
mysql>use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO \'root\'@\'%\' IDENTIFIED BY \'123456\' WITH GRANT OPTION;(将root用户开启远程访问权限)
开启远程访问权限“%”代表所有人
注意:在开启远程访问权限后也有可能访问不了,而报一个10060的错误
这个错误一般来说都是因为服务器防火墙的原因,所以,需要将服务器的端口加入到监听中
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
保存设置
/etc/init.d/iptables save
以上是关于centos7安装Mysql5.6的主要内容,如果未能解决你的问题,请参考以下文章