1、创建一个目录管理安装包
[root@localhost ~]# mkdir -p /script/tools
[root@localhost ~]# cd /script/tools
2、下载mysql二进制安装包及校验包(用于校验下载的包是否有更改)
[root@localhost tools]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@localhost tools]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz.md5
校验:[root@localhost tools]# md5sum -c mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz.md5
mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz: 确定
3、创建管理用户mysql
[root@localhost tools]# useradd -s /sbin/nologin -M mysql
-M:不创建用户目录
[root@localhost tools]# id mysql
uid=1003(mysql) gid=1003(mysql) 组=1003(mysql)
4、解压二进制包,创建软连接mysql
[root@localhost tools]# tar -zxf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@localhost tools]# mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql-5.7.23
[root@localhost tools]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.23 mysql
[root@localhost local]# cd mysql
[root@localhost mysql]# ls
bin COPYING docs include lib man README share support-files
5、创建数据库目录:
[root@localhost mysql]#mkdir data
6、设置权限
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql/
7、修改配置文件my.cnf
[root@localhost mysql]# find / -name my*.cnf
/etc/my.cnf
/etc/my.cnf.d/mysql-clients.cnf
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[client] //添加client
port = 3306 //添加端口
socket = /usr/local/mysql/mysql.sock //添加mysql.sock
[mysqld]
port = 3306 //添加端口
user = mysql //添加用户
#datadir=/var/lib/mysql
datadir=/usr/local/mysql/data //修改或添加数据库目录
#socket=/var/lib/mysql/mysql.sock
socket=/usr/local/mysql/mysql.sock //修改路径
basedir = /usr/local/mysql //添加安装目录
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
log-error=/var/log/mysqld.log //修改日志文件路径
pid-file=/var/run/mariadb/mariadb.pid
# include all files from the config directory
#
!includedir /etc/my.cnf.d
8、初始化数据库
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
2019-01-31T03:07:31.422669Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-31T03:07:31.632336Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-01-31T03:07:31.661220Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-01-31T03:07:31.763861Z 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: 59786955-2505-11e9-a594-000c29851a4e.
2019-01-31T03:07:31.764710Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-01-31T03:07:31.765930Z 1 [Note] A temporary password is generated for root@localhost: h,YChF6olC4y
初始化就生成root登录密码:h,YChF6olC4y
9、配置启动
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod 755 /etc/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --list mysqld
[root@localhost mysql]# service mysqld start
Starting MySQL. SUCCESS!
10、配置mysql环境变量/文件末尾添加/source 生效
[root@localhost ~]# vim /etc/profile
MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
[root@localhost ~]#source /etc/profile
11、登录mysql,修改密码
[root@localhost mysql]# mysql -uroot -p'h,YChF6olC4y'
mysql> set password=password('123456')
-> ;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
想让root在其他客户端也能管理数据库:
执行 : GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.44.%' IDENTIFIED BY '123456' ;
然后 执行:flush privileges;