[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql mysql
安装
[root@localhost mysql-5.7.24]# mkdir data
[root@localhost mysql-5.7.24]# ls
bin COPYING data docs include lib man README share support-files
// 将文件所有者该为mysql用户
[root@localhost mysql-5.7.24]# chown -R mysql:mysql ./
// 初始化,最后会打印mysql的初始化密码
[root@localhost mysql-5.7.24]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.24/ --datadir=/usr/local/mysql-5.7.24/data/
2018-12-25T11:45:08.464910Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-25T11:45:09.330575Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-25T11:45:09.608750Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-25T11:45:09.806830Z 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: 8838ec15-083a-11e9-989f-000c29f524c3.
2018-12-25T11:45:09.808541Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-25T11:45:09.822085Z 1 [Note] A temporary password is generated for root@localhost: iNo+Zmpew8Bu
// 将文件所有者修改为root,除了data的所有者还是mysql
[root@localhost mysql-5.7.24]# chown -R root .
[root@localhost mysql-5.7.24]# chown -R mysql data
[mysqld]
user=mysql
basedir=/usr/local/mysql-5.7.24/
datadir=/usr/local/mysql-5.7.24/data
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# 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/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
启动
[root@localhost mysql-5.7.24]# service mysqld start
// 表示mysql用户没有权限,也可以修改my.cnf中log-error,pid-file属性的路径到data路径下,这样就有权限了,无需进行下面操作,即可启动成功
//log-error=/usr/local/mysql-5.7.24/data/mysql.err
//pid-file=/usr/local/mysql-5.7.24/data/mysql.pid
Starting MySQL.2018-12-25T12:34:56.597258Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/usr/local/mysql-5.7.24/data/localhost.localdomain.pid).
// 创建配置文件中的日志目录及日志文件,并将所有者设置为mysql,设置权限
[root@localhost mysql-5.7.24]# mkdir /var/log/mariadb
[root@localhost mysql-5.7.24]# vim /var/log/mariadb/mariadb.log
[root@localhost mysql-5.7.24]# chown -R mysql /var/log/
[root@localhost mysql-5.7.24]# chmod -R 777 /var/log/
[root@localhost mysql-5.7.24]# service mysqld start
Starting MySQL... SUCCESS!
// 输入密码为初始化的密码
[root@localhost mysql-5.7.24]# mysql -u root -p
Enter password: