CentOS 7安装mysql 8.0.12数据库

步骤一:安装mysql依赖

yum install -y libaio numactl wget

步骤二:下载mysql社区版

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz

步骤三:创建mysql用户和用户组

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

步骤四:解压mysql文件

tar xvf mysql-* -C /usr/local
ln -s /usr/local/mysql-* /usr/local/mysql
cd /usr/local/mysql

步骤五:创建文件夹

mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb
chmod -R 750 /var/log/mariadb

步骤六:初始化mysql

将root初始化密码复制出来,等会登录mysql需要使用这个密码

bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup
bin/mysqld_safe --user=mysql
cp support-files/mysql.server /etc/init.d/mysqld

步骤七:分配mysql文件夹权限

chown -R mysql:mysql /usr/local/mysql*
chmod -R 751 /usr/local/mysql*

步骤八:启动mysql

service mysqld start

步骤九:更改mysql密码

bin/mysql -uroot -p #密码是刚刚执行(bin/mysqld --initialize --user=mysql)命令复制出来的密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
BY 'New_Password'; 
flush privileges;

可选项:开机自启动mysql数据库

systemctl enable mysqld

新建mysql用户并授权

CREATE USER 新建用户名 IDENTIFIED BY 密码;
GRANT SELECT, INSERT, UPDATE, DELETE ON 数据库名称 TO 新建用户名;
flush privileges;

参考文献:

https://zhuanlan.zhihu.com/p/38708106
https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
Tags:

Add a Comment

您的电子邮箱地址不会被公开。 必填项已用*标注