CentOS7下安装MySQL 5.6修改字符集为utf8并开放端口允许远程访问
卸载mariadb
#列出所有被安装的rpm package
rpm -qa | grep mariadb
#卸载
rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64
错误:依赖检测失败:
libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要
#强制卸载,因为没有--nodeps
rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64
安装mariadb
centos下yum暂时没有mysql-server直接安装包;
MariaDB是MySQL社区开发的分支,也是一个增强型的替代品.
yum -y install mariadb-server mariadb mariadb-devel
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
firewall-cmd --permanent --add-service mysql
systemctl restart firewalld.service
iptables -L -n|grep 3306
安装mysql
centos7中默认没有mysql的yum源,需要重新下载:
1.下载mysql的repo源
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
2.安装mysql-community-release-el7-5.noarch.rpm包
$sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
3.安装mysql
$ sudo yum install mysql-server
4.重置密码
需要先登录:
$mysql -u root
我使用的root,但也报错了:
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
$ sudo chown -R openscanner:openscanner /var/lib/mysql
重启mysql service:
$service mysqld restart
接下来设置密码:
$ mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql > exit;
开放3306端口
由于centos7使用firewalld而不是iptables,所以:
#开放3306
firewall-cmd --add-port=3306/tcp
#查看端口是否开放
firewall-cmd --query-port=3306/tcp
允许mysql远程访问
mysql默认是不允许远程访问的.
mysql -u root -p xxxx
mysql>use mysql
mysql>grant all privileges on *.* to 'root'@'%' identified by 'xxxxx(密码)';
mysql>flush privileges;