记录详细过程以备使用
1、创建群组及用户
obd:~ # groupadd mysql
obd:~ # useradd -g mysql mysql
2、创建相关目录
obd:~ # mkdir -p /opt/mysql/data
obd:~ # mkdir -p /opt/mysql/tmp
3、解压文件,并修改解压后的文件夹的名称
tar -zxvf mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.11-Linux-glibc2.5-x86_64 mysql
mv mysql /opt/
4、初始化数据库
bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data ---注意记下初始密码
obd:/opt/mysql # bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
2018-11-15T10:17:50.782341Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-15T10:17:51.195532Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-15T10:17:51.266087Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-15T10:17:51.336775Z 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: b553d43d-e8bf-11e8-84c5-000c296c182a.
2018-11-15T10:17:51.341835Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-15T10:17:51.344683Z 1 [Note] A temporary password is generated for root@localhost:!kt6ul-e&u3J
复制配置文件/etc/my.cnf
cp support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
[client]
socket = /opt/mysql/tmp/mysql.sock
[mysqld]
basedir = /opt/mysql
datadir = /opt/mysql/data
port = 3306
socket = /opt/mysql/tmp/mysql.sock
权限修改
chgrp -R mysql .
chown -R root .
chown -R mysql data
chown -R mysql.mysql ../mysql
开机启动
cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
/opt/mysql/bin
软连接
ln -s /opt/mysql/bin/mysql /usr/local/bin
ln -s /opt/mysql/bin/mysqladmin /usr/local/bin
ln -s /opt/mysql/bin/mysqld_safe /usr/local/bin
开启MySQL
service mysql start
mysql -u root -p ---初始密码
更改密码
alter user root@localhost identified by '123456';
更改IP登录权限
use mysql;
grant all privileges on *.* to root@'%' identified by "123456";
flush privileges; ---立即生效
select host, user from user;