赞
踩
目录
2、如果存在旧版本的mysql,则删除,如果报错,提示引用其他依赖时,使用强制删除
- # rpm查询MySQL信息
- [root@MT01 /]# rpm -qa | grep mysql
-
- # ps命令查询是否有mysql进程
- [root@MT01 /]# ps -ef | grep mysql
- root 7664 2638 0 11:16 pts/0 00:00:00 grep --color=auto mysql
- # 删除mysql
- [root@MT01 /]# rpm -e mysql
- # 强制删除
- [root@MT01 /]# rpm -e --nodeps mysql
官网下载地址:MySQL :: Download MySQL Community Server (Archived Versions)
复制下载地址链接:https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
- # 进入安装目录中
- [root@MT01 /]# mkdir /data/mysql
-
- # 新建安装目录
- [root@MT01 /]# cd /data/mysql
-
- # 使用wget下载安装包
- [root@MT01 mysql]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
- # tar解压
- [root@MT01 mysql]# tar -xvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
-
- # 移动文件夹并修改名称
- [root@MT01 mysql]# mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql
[root@MT01 mysql]# mkdir /usr/local/mysql/data
- # 进入mysql目录
- [root@MT01 ~]# cd /usr/local/mysql
-
- # 创建mysql用户组
- [root@MT01 mysql]# groupadd mysql
-
- # 添加mysql用户,禁止登录shell
- [root@MT01 mysql]# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
-
- [root@MT01 mysql]# chown -R mysql.mysql /usr/local/mysql/
- [root@MT01 mysql]# ll
- total 288
- drwxr-xr-x 2 mysql mysql 4096 Mar 31 11:54 bin
- drwxr-xr-x 2 mysql mysql 4096 Mar 31 11:59 data
- drwxr-xr-x 2 mysql mysql 4096 Mar 31 11:54 docs
- drwxr-xr-x 3 mysql mysql 4096 Mar 31 11:53 include
- drwxr-xr-x 5 mysql mysql 4096 Mar 31 11:54 lib
- -rw-r--r-- 1 mysql mysql 257591 Mar 26 2021 LICENSE
- drwxr-xr-x 4 mysql mysql 4096 Mar 31 11:53 man
- -rw-r--r-- 1 mysql mysql 566 Mar 26 2021 README
- drwxr-xr-x 28 mysql mysql 4096 Mar 31 11:54 share
- drwxr-xr-x 2 mysql mysql 4096 Mar 31 11:54 support-files
[root@MT01 mysql]# vim /etc/my.cnf
按 i 进入编辑模式后,加入环境配置,可直接删除原配置,粘贴下方配置
- [client]
- # 默认字符集
- default-character-set=utf8mb4
- # socket通信设置
- socket=/storage/db/mysql/mysql.sock
-
- [mysql]
- # 默认字符集
- default-character-set=utf8mb4
- # socket通信设置
- socket=/storage/db/mysql/mysql.sock
-
- [mysqld] # 服务器配置
- # mysql的安装目录
- datadir=/usr/local/mysql
- # mysql数据库数据存放目录
- datadir=/usr/local/mysql/data
- # 指定MySQL允许的最大连接进程数。如果在访问数据库时经常出现"Too Many Connections"的错误提 示,则需要增大该参数值
- max_connections=200
- # 服务端默认字符集
- character-set-server=utf8mb4
- # 初始连接字符集
- init-connect='SET NAMES utf8'
- # 默认存储引擎INNODB
- default-storage-engine=INNODB
- # 端口号
- port=3306
- # socket通信设置
- socket=/usr/local/mysql/mysql.sock
- # 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/mariadb/mariadb.log
- pid-file=/var/run/mariadb/mariadb.pid
-
- #
- # include all files from the config directory
- #
- !includedir /etc/my.cnf.d
修改完成之后,按 ESC 键,输入:wq 回车
进行保存
# bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql --initialize
- [root@MT01 mysql]# bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql --initialize
- bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
这个时候执行如果抛错error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory,则是缺少对应的文件,使用yum安装
- [root@MT01 mysql]# yum install -y libaio
-
- [root@MT01 mysql]# bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql --initialize
此处需要注意记录生成的临时密码,如上文结尾处的:a5jT1vx+<SBW
- [root@MT01 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
-
- [root@MT01 mysql]# chkconfig --add mysql
[root@MT01 mysql]# service mysql start
发现报错了,错误是因为没有/var/log/mariadb/mariadb.log这个文件的权限,加一下文件权限
- [root@MT01 mysql]# mkdir /var/log/mariadb
- [root@MT01 mysql]# touch /var/log/mariadb/mariadb.log
- [root@MT01 mysql]# chown -R mysql.mysql /var/log/mariadb/
再次运行就成功了!
- [root@MT01 bin]# mysql -u root -p
-
- # 如果提示-bash: mysql: command not found,执行以下命令,没有提示错误无需执行
- [root@MT01 bin]ln -s /usr/local/mysql/bin/mysql /usr/bin
输入第7步生成的临时密码进行登录
alter user 'root'@'%' identified by '密码';
flush privileges; # 刷新权限
- # 开放root账户所有权限
- mysql> grant all privileges on *.* to 'root'@'%' identified by '你的root账户密码';
修改前
修改后
如果是虚拟机
- # 查看开放端口
- netstat -an|grep 3306
-
- # 如果没有开放3306
- firewall-cmd --list-ports
-
- # 防火墙开启3306端口
- firewall-cmd --zone=public --add-port=3306/tcp --permanent
-
- # 重新防火墙
- firewall-cmd --reload
云服务器,需要再安全组中开放3306端口号
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。