1.数据库下载地址
https://downloads.mysql.com/archives/community/
2.下载mysql安装包到 /usr/local/ 目录
(1)解压到当前目录下
tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
(2)重命名
mv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
(3)创建mysql用户组和用户并修改权限
groupadd mysql
useradd -r -g mysql mysql
(4)创建数据目录并赋予权限
mkdir -p /data/mysql
chown mysql:mysql -R /data/mysql
(5)配置my.cnf
bind-address=0.0.0.0
port=3306
user=mysql
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
(6)初始化
cd /usr/local/mysql/bin
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
如果出现如下错误
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
执行
yum -y install numactl
再重新初始化
(7)启动mysq
先将mysql.server放置到/etc/init.d/mysql中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动
service mysql start
(8)登录mysql 并修改密码
登录前先执行
ln -s /usr/local/mysql/bin/mysql /usr/bin
再登录
mysql -u root -p
执行以下命令修改密码
alter user user() identified by "xxxx";
(9)开启root账号远程连接权限
登录数据库执行以下命令
use mysql
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
注:如果远程连接失败,查询服务器3306端口是否开放;