阿里云centos7.5 安装mysql-5.7(glibc版)

1、下载tar包,这里使用wget从官网下载
https://downloads.mysql.com/archives/community/ 下载

wget https://downloads.mysql.com/archives/get/file/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

2、将mysql安装到/usr/local/mysql下

解压

tar -zxvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

移动并且重命名

mv mysql-5.7.27-linux-glibc2.12-x86_64 /usr/local/mysql

3、新建data目录

mkdir /usr/local/mysql/data

4、新建mysql用户、mysql用户组

添加mysql用户组

groupadd mysql

添加mysql用户到mysql组

useradd mysql -g mysql

5、将/usr/local/mysql的所有者及所属组改为mysql

chown -R mysql.mysql /usr/local/mysql

6、配置

/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

如果出现以下错误:

2020-01-09 09:55:45 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-01-09 09:55:46 [ERROR] Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2020-01-09 09:55:46 [ERROR] Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
– server log begin –

– server log end –

则使用以下命令:

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

如果出现以下错误:

/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

则执行以下命令:

yum install libaio* -y

完成后继续安装:

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize

编辑/etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8

#跳过密码验证,忘记密码 可以设置,然后修改密码,再关闭(即注释代码)
skip-grant-tables

#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/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

7、开启服务

将mysql加入服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

开机自启

chkconfig mysql on

开启

service mysql start

8、设置密码

#登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)

/usr/local/mysql/bin/mysql -u root -p

操作mysql数据库

mysql> use mysql;

修改密码

mysql> update user set authentication_string=password('你的密码') where user='root';
mysql> flush privileges;
mysql> exit;

9、将/etc/my.cnf中的skip-grant-tables删除

10、(如果登录不了)登录再次设置密码(不知道为啥如果不再次设置密码就操作不了数据库了)

如果出现以下错误:

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

/usr/local/mysql/bin/mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '修改后的密码';
mysql> exit;

11、授权其他机器登陆,允许远程连接

/usr/local/mysql/bin/mysql -u root -p

mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
mysql> eixt;

12、添加快捷方式 软连接

ln -s /usr/local/mysql/bin/mysql /usr/bin
发布了4 篇原创文章 · 获赞 2 · 访问量 189

猜你喜欢

转载自blog.csdn.net/OuYz12/article/details/103899979