目录
1、下载
下载地址:
MySQL :: Download MySQL Community Serverhttps://dev.mysql.com/downloads/mysql/5.7.html
或者在这里下载:
下载后,上传到服务器:
2、安装
检查是否安装过mysql
rpm -qa|grep mysql
没有安装过
查看系统自带的Mariadb
rpm -qa|grep mariadb
卸载系统自带的Mariadb
创建mysql 用户组和用户
groupadd mysql
useradd -r -g mysql mysql
执行命令:
tar -xvf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /opt
切换到/ope目录
修改名称
mv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql5.7
修改权限,用户组
chown -R mysql:mysql /opt/mysql5.7
chmod -R 755 /opt/mysql5.7
进入:/opt/mysql5.7/bin,执行
./mysqld --initialize --user=mysql --datadir=/opt/mysql5.7/data --basedir=/opt/mysql5.7
新建文件:
vi /etc/my.cnf
写入以下内容:
[mysqld]
datadir=/opt/mysql5.7/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1
授权
chmod -R 775 /etc/my.cnf
修改文件:
vi /opt/mysql5.7/support-files/mysql.server
启动服务:
/opt/mysql5.7/support-files/mysql.server start
root 23261 21419 0 22:01 pts/0 00:00:00 grep --color=auto mysqld
[root@node05 support-files]# /opt/mysql5.7/support-files/mysql.server start
my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 1!
my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Starting MySQL.my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 1!
my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 1!
my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Logging to '/opt/mysql5.7/data/node05.err'.
ERROR! The server quit without updating PID file (/opt/mysql5.7/data/node05.pid).
报错了,原因有
1、数据目录mysql用户没有权限
2、/etc/my.cnf配置文件配置有错,[mysqld]下设置这一行:datadir = /opt/mysql/data
3、还有就是/etc/格式问题my.cnf
检查启动成功后:
添加软连接,并重启mysql 服务
ln -s /opt/mysql5.7/support-files/mysql.server /etc/init.d/mysql
ln -s /opt/mysql5.7/bin/mysql /usr/bin/mysql
service mysql restart
3、连接mysql
用户名是:root,密码是刚才安装过程中生成的密码
修改root密码:
set password for root@localhost = password('root');
开放远程连接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
4、设置开机启动
执行以下命令
//将服务文件拷贝到init.d下,并重命名为mysql
cp /opt/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
//赋予可执行权限
chmod +x /etc/init.d/mysqld
//添加服务
chkconfig --add mysqld
//显示服务列表
chkconfig --list
如果不通,关闭防火墙:
#开启防火墙
systemctl start firewalld
#关闭防火墙
systemctl stop firewalld
或者
//开放3306端口命令
firewall-cmd --zone=public --add-port=3306/tcp --permanent
//配置立即生效
firewall-cmd --reload
至此,安装成功