1.查看服务器有没有残留的mysql数据并删除
rpm -qa |grep -i mysql
find / -name mysql
有则卸载
rpm -e 目标文件(rpm -e --nodeps 强制卸载)
rm -rf 文件名 ----------删除文件
检查否存在 mariadb 数据库,如有,卸载之,卸载同上
rpm -qa | grep mariadb
2.解压mysql压缩包
tar -zxvf 压缩包名字
3.复制到usr/local/mysql 并命名为mysql
mv mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql
4.在mysql目录下创建data目录存放东西
cd /usr/local/mysql
mkdir data
5.创建用户组和用户
groupadd mysql
useradd -r -g mysql mysql
userdel mysql ---------删除组
6.为mysql目录修改用户权限
chown -R mysql:mysql /usr/local/mysql/
cd ../
ll
7.配置文件并将mysql初始化,并记录初始密码
配置mysql(my.cnf)
vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
pid-file=/usr/local/mysql/data/mysql.pid
log-error=/usr/local/mysql/data/mysqld.log
socket=/tmp/mysql.sock
character-set-server=utf8mb4 -----------默认字符集
lower_case_table_names=1 -----------关闭大小写敏感
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default_authentication_plugin=mysql_native_password
#skip-grant-tables
保存退出:esc+shift+; wq
cd mysql/bin/
./mysqld --user=mysql --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
记录初始密码如:0,bilXksleyt
8.mysql加入开机启动
cd /usr/local/mysql/
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list
//查看自启是否添加成功
sudo /etc/init.d/mysql start --mysql自启
9.配置环境变量
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib //在末尾加入
保存退出
source /etc/profile //重新刷新刚刚修改的文件
10.启动mysql
systemctl restart mysqld
再次安装时可能出现线程被占用的情况
ps -ef|grep mysql ----------查看线程
kill -9 线程号 -------------杀死线程
ps -ef|grep mysql
mysql -u root -p
输入刚刚的密码
报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (40)
改/tmp/mysql.sock
vim /etc/my.cnf
修改socket=/tmp/mysql.sock
systemctl restart mysql //刷新一下
ps -ef|grep mysql
mysql -u root -p
输入刚刚的密码
重置密码
ALTER user 'root'@'localhost' IDENTIFED WITH mysql_native_password BY 'Y6r~1EY)9J)X';
或者
mysql8 ---------ALTER USER 'root'@'localhost' IDENTIFIED by 'Y6r~1EY)9J)X';
或者
set password for root@localhost=password('123456');
flush privileges;
quit //退出
再次修改密码
select host, user from user -----------查看用户信息
ALTER USER 'root'@'%' IDENTIFIED by 'CY%z8LG8!b';
flush privileges;
重新登录
mysql -u root -p123456
quit
sjkRZsruz4)Y
navicat链接Linux数据库
service mysqld start --启动mysql
登录mysql
use mysql --给其他电脑授权链接权限
1.GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Y6r~1EY)9J)X' WITH GRANT OPTION;
2.mysql8 -------------update user set user.Host='%' where user.User='root';
FLUSH PRIVILEGES;
exit
然后去navicat使用端口链接mysql就ok
没链接上
方法1.关闭防火墙
systemctl status firewalld -------查看防火墙状态
systemctl stop firewalld ------------关闭防火墙
systemctl start firewalld ----------开启防火墙
firewall-cmd --reload ---------------重启防火墙
方法2.放行端口(推荐)
查看防火墙状态 -------查看防火墙状态
firewall-cmd --query-port=端口号/tcp ---------查看某个端口是否放行
firewall-cmd --zone=public --add-port=3306/tcp --permanent -------------放行指定端口号
systemctl restart firewalld.service -----------------重启防火墙
firewall-cmd --reload ----------------重载配置
firewall-cmd --query-port=3306/tcp ---------查看某个端口是否放行
firewall-cmd --list-ports -----------------查看目前所有开放的端口