Linux安装mysql-5.7.26版本
一、下载 mysql及上传至linux
二、检查mysql是否已安装
第一步:查看mysql安装
rpm -qa|grep -i mysql
第二步:卸载Mysql
rpm -ev --nodeps 【上一步查询到的所有名称】
查看是否卸载完成:再次执行 rpm-qa|grep -i mysql
删除关于mysql相关的文件夹
查找根目录下的所有的msql名称的文件和文件夹
find / -name mysql
把查找出的目录删除 rm -rf 路径
三、安装mysql
第一步:解压
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
第二步:解压放入你想安装的目录,然后移动并改名
mv -v mysql-5.7.26-linux-glibc2.12-x86_64/* /usr/local/mysql
第三步:创建组
groupadd mysql
第四步:创建用户
useradd -r -g mysql mysql
第五步:将安装目录所有者及所属组改为mysql ,这个根据自己的目录来
chown -R mysql.mysql /usr/local/mysql
第六步:在mysql目录下创建data文件夹
mkdir data
第七步:初始化数据库
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
第八步:完成初始化后编辑配置文件 /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
#跳过密码验证,忘记密码 可以设置,然后修改密码,再关闭
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# include all files from the config directory
!includedir /etc/my.cnf.d
第九步:将mysql加入到服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
第十步:设置开机启动.
chkconfig mysql on
第十一步:启动mysql
service mysql start
如果安装过程中报错
my_print_defaults: Can't read dir of '/etc/my.cnf.d/'
解决办法:报错解决方案
第十二步:设置mysql密码
配置环境变量
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
配置完成后记得source /etc/profile
登录mysql
mysql -u root -p
use mysql;
update user set authentication_string=password('你的密码') where user='root';
flush privileges;
exit
将 /etc/my.cnf 中skip-grant-tables删除或注释掉 然后重启Mysql
service mysql restart
第十三步:设置允许远程连接
mysql -u root -p
输入密码
use mysql;
如果进行操作出现下面的提示:
You must reset your password using ALTER USER statement before executing this statement
exit
退出;
就重新设置一遍密码(原密码一样):
mysql -u root -p
mysql> alter user 'root'@'localhost' identified by'你的密码';
exit;
再次设置远程连接
mysql -u root -p
use mysql;
update user set host='%' where user = 'root';
flush privileges;
exit;
关闭防火墙
查看状态: systemctl status firewalld
启动: systemctl start firewalld
关闭: systemctl stop firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld
关闭防火墙后用navicat连接