获取mysql 二进制软件包
wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.22-el7-x86_64.tar.gz
tar -xf mysql-5.7.22-el7-x86_64.tar.gz
mv mysql-5.7.22-el7-x86_64 /usr/local/
ln -s /usr/local/mysql-5.7.22-el7-x86_64/ /usr/local/mysql
cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
创建mysql用户及组
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
创建初始化所需的目录
[root@mysql local]# mkdir -p /var/lib/mysql
[root@mysql local]# chown -R mysql.mysql /var/lib/mysql
[root@mysql local]# mkdir -p /var/log/mariadb/
[root@mysql local]# chown -R mysql.mysql /var/log/mariadb/
[root@mysql local]# touch /var/log/mariadb/mariadb.log
[root@mysql local]# chown -R mysql.mysql /var/log/mariadb/
[root@mysql local]# mkdir -p /var/run/mariadb/
[root@mysql local]# chown -R mysql.mysql /var/run/mariadb/
配置
结尾添加下面的环境变量
[root@mysql local]# vim /etc/profile
export MYSQL=/usr/local/mysql/bin/
export PATH="${MYSQL}:${PATH}"
使环境变量生效
[root@mysql local]# source /etc/profile
安装依赖
[root@mysql local]# yum -y install libaio
初始化数据
[root@mysql local]# mysqld --initialize
2018-07-29T09:12:33.373161Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-07-29T09:12:33.951747Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-07-29T09:12:34.060407Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-07-29T09:12:34.120200Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8775432e-930f-11e8-b03c-000c2939e151.
2018-07-29T09:12:34.121440Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-07-29T09:12:34.122642Z 1 [Note] A temporary password is generated for root@localhost: k/lhzl)&z5qK(密码)
启动并修改密码
root@mysql local]# chown -R mysql.mysql /var/lib/mysql
[root@mysql local]# /etc/init.d/mysqld start
[root@mysql local]# mysqladmin -uroot -p'k/lhzl)&z5qK' password hjy123 -S /var/lib/mysql/mysql.sock
最后授权
mysql> grant all on *.* to root@'%' identified by 'hjy123';
网友评论