# 下载 mysql
# 上传 mysql 到 /usr/local
路径
我安装的 mysql 版本为
mysql-5.7.26
# 卸载 Centos7 自带的Maridb数据库
查询所安装的MariaDB组件
rpm -qa | grep mariadb
此时会出现
mariadb-libs-5.5.52-1.el7.x86_64
卸载数据库
yum -y remove mari*
删除数据库文件
rm -rf /var/lib/mysql/*
# 安装 mysql
1、cd 到 /usr/local
cd /usr/local
2、解压 mysql
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
3、重命名文件夹为 mysql
mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql
4、添加系统mysql组
groupadd mysql
5、添加mysql用户
useradd -r -g mysql mysql
6、创建数据目录
mkdir /usr/local/mysql/data
7、修改当前目录拥有者为mysql用户
chown -R mysql:mysql /usr/local/mysql
8、切换到mysql目录
cd /usr/local/mysql
9、初始化mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
如果出现
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
这个报错解决方法
yum install -y libaio
然后重新初始化 mysql
如果运行
yum install -y libaio
报错Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Package libaio-0.3.109-13.el7.x86_64 already installed and latest version Nothing to do
或者报错Loaded plugins: fastestmirror, langpacks No Match for argument: libnuma.so.1 No Packages marked for removal
解决办法
yum -y install numactl.x86_64
然后重新初始化 mysql
10、创建RSA private key
bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
11、创建my.cnf文件
vim /etc/my.cnf
输入以下内容
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
#不区分大小写
lower_case_table_names = 1
#不开启sql严格模式
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
12、添加开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
13、修改 /etc/init.d/mysqld
vim /etc/init.d/mysqld
添加路径 在46行
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
14、启动mysql
service mysqld start
15、加入开机启动
chkconfig --add mysqld
16、登录修改密码(密码是初始化mysql时的密码)
mysql -uroot -p
如果出现
-bash: mysql: command not found
报错
解决方法:需要添加软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin
然后再执行一遍mysql -uroot -p
17、修改mysql密码
set password=password("root");
18、远程登录设置
use mysql
update user set host='%' where user='root';
FLUSH PRIVILEGES;
参考博客: