二进制包安装Mysql

(1).准备工作

  前往mysql官网下载二进制安装包,https://dev.mysql.com/downloads/mysql/5.7.html#downloads(注意:选择操作系统时选Linux-Generic)。我这里下载的是mysql-5.7.26-linux-glibc2.12-x86_64。

  Mysql5.7参考手册-2.2使用通用二进制文件在Unix/Linux上安装Mysql:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

  在下载和上传的过程中,可以先检查系统中的Mysql或mariadb,如果存在将其卸载

[root@youxi1 ~]# rpm -qa | grep mysql
[root@youxi1 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@youxi1 ~]# yum -y remove mariadb-libs.x86_64 

  接着创建mysql的专用用户,官方使用的是/bin/false一样也可以。

[root@youxi1 ~]# useradd -M -s /sbin/nologin -r mysql  //-M不创建主目录,-s /sbin/nologin不允许登录,-r创建的是系统用户

  安装依赖包,CentOS7好像自带可以不装。

[root@youxi1 ~]# yum install libaio

  官方说明:版本大于等于5.7.19,对通用Linux构建添加了对非统一内存访问(NUMA)的支持,该构建现在依赖于 libnuma库。

(2).解压二进制包,创建数据目录,修改mysql文件所属主和所属组,然后初始化数据库

[root@youxi1 ~]# tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/  //解压
[root@youxi1 ~]# cd /usr/local/
[root@youxi1 local]# mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql  //文件夹重命名,不然配置文件要写很长一段
[root@youxi1 local]# cd mysql/
[root@youxi1 mysql]# mkdir data  //创建数据目录
[root@youxi1 mysql]# chown -R mysql.mysql /usr/local/mysql/  //修改所属主和所属组
[root@youxi1 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  //初始化
2019-06-26T07:12:23.842578Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-06-26T07:12:25.699399Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-06-26T07:12:25.920250Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-06-26T07:12:25.998106Z 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: c03a1dc7-97e1-11e9-acca-000c29e6d627.
2019-06-26T07:12:26.041964Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-06-26T07:12:26.044143Z 1 [Note] A temporary password is generated for root@localhost: jcJ3Ncguf:ql  //显示root@localhost第一次登录的随机密码

(3).编辑配置文件/etc/my.cnf

[root@youxi1 mysql]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
socket=/usr/local/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/usr/local/mysql/mysql.sock
[client]
socket=/usr/local/mysql/mysql.sock

(4).配置环境变量,并刷新

[root@youxi1 mysql]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@youxi1 mysql]# . /etc/profile.d/mysql.sh  //两种刷新方式,还可以使用source /etc/profile.d/mysql.sh

(5).生成启动脚本,并启动mysql

[root@youxi1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@youxi1 mysql]# chmod +x /etc/init.d/mysqld
[root@youxi1 mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql  //在第46~47行
datadir=/usr/local/mysql/data
[root@youxi1 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

(6).测试,并修改root密码

[root@youxi1 mysql]# mysql -uroot -p'jcJ3Ncguf:ql'
mysql> set password for root@localhost=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show variables like 'validate_password%';  //可以看到没有密码复杂度插件
Empty set (0.01 sec)

mysql> exit
Bye
[root@youxi1 mysql]# mysql -uroot -p123456
mysql>

  

posted @ 2019-06-26 15:41  苦逼运维  阅读(5266)  评论(0编辑  收藏