1.检查系统是否装有mysql
rpm -qa | grep mysql
返回空值,说明没有安装
2.删除可用
yum remove mysql
3.下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
4.安装mysql-community-release-el7-5.noarch.rpm包
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装这个包后,会获得两个mysql的yum repo源:
/etc/yum.repos.d/mysql-community.repo
/etc/yum.repos.d/mysql-community-source.repo
5.安装mysql
sudo yum install mysql-server
安装后再次查看mysql
rpm -qa | grep mysql
6.安装完成后,没有密码,需要重置密码
chown root /var/lib/mysql/
- 修改/etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1
- 重启mysqld 服务:systemctl restart mysqld
- 使用 root 用户登录到 mysql:mysql -uroot
- 重置密码
use mysql;
update user set password=password(‘123456’) where user=‘root’;
exit;
service mysqld restart - 修改/etc/my.cnf,删除skip-grant-tables=1
- 测试
mysql -uroot -p123456
设置数据库用户在所有ip下以及在本地可访问,以下用root用户做演示
grant all privileges on . to root@"%" identified by “你的密码”;
grant all privileges on . to root@“localhost” identified by “你的密码”;
flush privileges;
9.查询数据库编码格式,确保是UTF-8
show variables like “%char%”;
set names utf8;
10.关闭防火墙
service firewalld stop
[root@localhost ~]# systemctl stop firewalld #关闭防火墙
[root@localhost ~]# systemctl status firewalld #查看状态
[root@localhost ~]# systemctl disable firewalld #开机自动关闭
netstat -ntlp
查看tomcat默认端口8080是否开启