1. 下载mysql5.7.31 (这里选择的是通用Linux版本)
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
2. 卸载自带的mariadb和mysql
检查是否安装了mariadb和mysql,有时候默认安装了
rpm -qa | grep mariadb
rpm -qa | grep mysql
如果没有,就可以安装mysql,如果有,需要先卸载(remove后为上面命令查询到的内容,全文件名,我这里没有,没法展示)
yum remove mariadb-*
3. 将下载好的文件传到linux服务器
使用SecureCRT把mysql安装包上传到linux服务器,这里上传到/usr/local
rz
解压缩
tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
重命名
mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql
4. 添加mysql用户,修改mysql目录权限,并用此用户执行应用
useradd -s /bin/false -M mysql
cd /usr/local/mysql
chown -R mysql:mysql mysql
5. 在/etc/下新建 my.cnf文件
添加配置
[mysqld]
# binlog
log-bin=/usr/local/mysql/logs/mysql-bin.log
expire-logs-days=14
max-binlog-size=500M
server-id=1
# GENERAL
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
user=mysql
default-storage-engine=InnoDB
character-set-server=utf8
lower_case_table_names = 1
explicit_defaults_for_timestamp=true
[mysqld_safe]
log-error=/usr/local/mysql/mysql-error.log
pid-file=/usr/local/mysql/mysqld.pid
[client]
socket=/usr/local/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
对应的文件自己要手动添加
6. 安装mysql,进入mysql目录执行以下命令
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
出现以下信息,代表成功,要保存一下密码
7. 拷贝启动程序,将mysql的启动程序拷贝到/etc/init.d/目录下
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
8. 安装完,启动mysql服务
service mysqld start
9. 配置环境变量,编辑/etc/profile,方便在任何地方用mysql命令
vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
配置文件生效
source /etc/profile
10. 首次登录没有密码,提示输入密码时,输入第6步安装时生成的密码
mysql -uroot -p
alter user ‘root‘@‘localhost‘ identified by ‘root‘;
flush privileges;
开启远程访问
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘root‘ WITH GRANT OPTION;
11. mysql服务常用命令
service mysqld start #启动
service mysqld stop #关闭
service mysqld restart #重启
service mysqld status #查看运行状态