安装mysql5.7
参考链接:https://blog.csdn.net/weixin_38822045/article/details/91447250
安装包:mysql-5.7.26-linux-glibc2.12-x86_64.tar
- 查看mysql有无预安装 ----无
rpm -qa | grep -i mysql (已安装执行第二步,未安装则跳过)
- 查找根目录下的所有mysql名称的文件和文件夹并删除
find / -name mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql
find / -name mysql
rm -rf /etc/selinux/targeted/active/modules/100/mysql
- 由于官网下载缓慢,已从参考链接提供的网盘中下载好了压缩包。将其通过WINSCP拷贝到/tmp路径下
- 解压压缩包
cd /tmp
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
- 将解压后的文件转移到安装目录并重命名(这里是/usr/local/ 不建议修改)
mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
- 创建用户和用户组
groupadd mysql
useradd -r -g mysql mysql
- 修改文件文件夹所有者和所有组为mysql
cd /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql/
ll
- 到mysql目录下创建data文件夹
cd /usr/local/mysql
mkdir data
- 初始化数据库
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
- 编辑配置文件/etc/my.cnf
cd /etc
cp my.cnf my.cnf_bak
vi 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
- 设置开机启动 启动mysql
chkconfig mysql on
service mysql start
- 设置mysql密码配置环境变量
vi /etc/profile
添加一行内容如下:
------------------------------------------------------------------------------------
export PATH=$PATH:/usr/local/mysql/bin
-------------------------------------------------------------------------------------
使环境变量立即生效
source /etc/profile
- 配置完环境变量以后登录数据库,设置密码
mysql -u root -p
回车
use mysql
update user set authentication_string=password("111111") where user="root";
flush privileges;
exit
- 将/etc/my.cnf 中skip-grant-tables删除或注释掉 然后重启Mysql 密码生效。
vi /etc/my.cnf
--------------------------------------
#skip-grant-tables
-------------------------------------
service mysql restart
- 再次进入数据库操作 进行如下操作
mysql -u root -p
111111
alter user "root"@"localhost" identified by "111111";
exit
17、登录数据库 设置远程连接
mysql -u root -p
111111
use mysql;
update user set host="%" where user = "root";
flush privileges;
exit
- 开放防火墙3306端口 测试telnet 或mysql连接
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
- WINDOWS主机使用navicatl 测试连接 (提供的安装包为试用版)