安装
- 查看系统是否安装了mysql软件
rpm -qa|grep -i mysql
- 下载rpm包并安装
wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
rpm -ivh mysql57-community-release-el7-7.noarch.rpm
- yum安装mysql
yum install mysql-server
yum install mysql-devel
yum install mysql
- 检查mysql的状态
systemctl status mysqld
- 数据库初始化
mysqld --initialize --user=mysql
- 启动MySQL数据库
systemctl start mysqld
- 查看mysql状态
systemctl status mysqld
- 查看mysql临时密码
grep 'temporary password' /var/log/mysqld.log
[root@iZbp16mt5q458fcs0sgb8dZ java]# grep 'temporary password' /var/log/mysqld.log
2021-03-31T03:26:51.646893Z 1 [Note] A temporary password is generated for root@localhost: G6ygwurfab?,
- 使用临时密码登陆
mysql -uroot -p临时密码
- 修改密码,然后刷新
ALTER USER USER() IDENTIFIED BY 'newPassword';
flush privileges;
开放端口
- 查看防火墙状态
firewall-cmd --state
- 查看开放的端口
firewall-cmd --list-ports
- 开放3306端口,后刷新
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload
乱码解决方案
- 查看默认的编码格式
show variables like "%char%";
- 设置默认编码格式
SET NAMES utf8
- 修改配置文件/etc/my.cnf,然后重启
[mysqld]
character-set-server=utf8
--------------------
systemctl restart mysqld.service
常见问题
-
ubuntu中mysql远程连接错误2003
编辑 MySQL 服务器的配置文件 /etc/mysql/mysql.conf.d/mysqld.cnf,找到 bind-address 行并将其注释掉,然后重新启动 MySQL 服务器。
-
navicat 连接错误 2059
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
-
The user specified as a definer (‘root’@‘%’) does not exist
create user 'root'@'%' identified by 'password'; grant all privileges on *.* to 'root'@'%';