1.检查服务器自带的mysql
yum list installed|grep mysql
2.移除mysql,以免重新安装冲突
yum remove 自带的mysql名
3. 下载mysql的yum源
CentOS6的MySQL:wget https://dev.mysql.com/get/mysql80-community-release-el6-3.noarch.rpm
CentOS7的MySQL:wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
4. 安装rpm包,安装之后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
5. 安装mysql
sudo yum install mysql-server
6.设置服务器字符编码,配置文件默认为: /etc/my.cnf
#mysql5.5及以下版本
[mysqld]
default-character-set=utf8
[client]
default-character-set=utf8
#mysql5.5以上版本
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
启动服务器后查询结果如下,说明字符编码设置成功。
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)
7.启动mysql服务器
service mysqld start #启动
service mysqld stop #停止
service mysqld restart #重启
8.重置密码:默认root账号没有密码
mysql -u root
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > flush privileges;
mysql > exit;
9. 开放3306端口
sudo vim /etc/sysconfig/iptables
添加以下内容:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
保存后重启防火墙:
sudo service iptables restart
这样从其它客户机也可以连接上mysql服务了。
————————————————
版权声明:本文为CSDN博主「喵在乎」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_36253081/article/details/113379428