注:文中所写的安装过程均在CentOS-6.5-x86_64-minimal下通过测试
Hyper -v 安装CentOS 参考 https://www.jianshu.com/p/c55795bb1f38
1.检测系统是否已经安装过mysql或其依赖,若已装过要先将其删除,否则第4步使用yum安装时会报错:
1 # yum list installed |grep mysql
2 mysql-libs.i6865.1.71-1.el6 @anaconda-CentOS-201311271240.i386/6.5
3 # yum -y remove mysql-libs.i686
2.从mysql的官网下载mysql57-community-release-el6-5.noarch.rpm(注意这里的el6-5即适配RHEL6.5的版本,如果下载了其它版本后面的安装过程中可能会报错):
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
3.安装第一步下载的rpm文件:
yum install mysql-community-release-el6-5.noarch.rpm
安装成功后,我们可以看到/etc/yum.repos.d/目录下增加了以下两个文件
1 # ls /etc/yum.repos.d
2 mysql-community-source.repo
3 mysql-community.repo
查看mysql57的安装源是否可用,如不可用请自行修改配置文件(/etc/yum.repos.d/mysql-community.repo)使mysql57下面的enable=1
若有mysql其它版本的安装源可用,也请自行修改配置文件使其enable=0
1 # yum repolist enabled | grep mysql
2 mysql-connectors-community MySQL Connectors Community 13
3 mysql-tools-community MySQL Tools Community 18
4 mysql57-community-dmr MySQL5.7Community Server Development Milesto 65
4.使用yum安装mysql:
yum install mysql-community-server
5.启动mysql服务:
service mysqld start
修改root 密码
/usr/bin/mysqladmin -u root password 'new-password'
6.查看mysqld是否开机自启动,并设置为开机自启动:
1 chkconfig --list | grep mysqld
2 chkconfig mysqld on
7.修改字符集为UTF-8:
vi /etc/my.cnf
在[mysqld]部分添加:
character_set_server=utf8
在文件末尾新增[client]段,并在[client]段添加:
default-character-set=utf8
修改好之后重启mysqld服务:
service mysqld restart
查看修改结果:
mysql> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> quit
MySQL 安装结束。
Linux安装MySQL,默认不允许远程登录。
执行以下命令开启远程登录:
1 # mysql -uroot -p
Enter password:
2 mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
3 mysql> grant all privileges on *.* to 'root'@'%' identified by 'new-password' with grant option;
Query OK, 0 rows affected (0.00 sec)
4 mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
PS:如果还是报错检查一下防火墙是否开启了3306端口
/etc/init.d/iptables status
配置防火墙:
vi /etc/sysconfig/iptables
插入:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
添加好之后防火墙规则如下所示:
重启防火墙:
开启防火墙(重启后永久生效):chkconfig iptables on
关闭防火墙(重启后永久生效):chkconfig iptables off
开启防火墙(即时生效,重启后失效):service iptables start
关闭防火墙(即时生效,重启后失效):service iptables stop
重启防火墙:service iptables restart
Navicat for MySQL连接MySQL :
删除user表中user列为空数据:
drop user ''@localhost
drop user ''@localhost.localdomain
主要参考博文:
https://www.cnblogs.com/lzj0218/p/5724446.html
http://blog.sina.com.cn/s/blog_544f18310102w8m0.html