mysql安装流程
2018-04-16 本文已影响0人
华龙007
[root@n5 ~]# rpm -q mariadb-server mariadb #如果之前安装过mariadb,需要卸载
[root@n5 ~]# ls #把安装包上传到root目录下
anaconda-ks.cfg mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
[root@n5 ~]# useradd -r mysql #创建一个系统用户mysql
[root@n5 ~]# id mysql
uid=997(mysql) gid=995(mysql) groups=995(mysql)
[root@n5 ~]# tar xf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local #展开安装包
[root@n5 ~]# cd /usr/local/
[root@n5 local]# ln -sn mysql-5.7.18-linux-glibc2.5-x86_64/ mysql #制作链接文件
lrwxrwxrwx 1 root root 35 Apr 12 23:20 mysql -> mysql-5.7.18-linux-glibc2.5-x86_64/
[root@n5 local]# cd mysql
[root@n5 mysql]# chown -R root.mysql ./\* #修改mysql所有文件属组为mysql
[root@n5 mysql]# ll
total 36
drwxr-xr-x 2 root mysql 4096 Apr 12 23:16 bin
-rw-r--r-- 1 root mysql 17987 Mar 18 2017 COPYING
drwxr-xr-x 2 root mysql 55 Apr 12 23:16 docs
drwxr-xr-x 3 root mysql 4096 Apr 12 23:16 include
drwxr-xr-x 5 root mysql 229 Apr 12 23:16 lib
drwxr-xr-x 4 root mysql 30 Apr 12 23:16 man
-rw-r--r-- 1 root mysql 2478 Mar 18 2017 README
drwxr-xr-x 28 root mysql 4096 Apr 12 23:16 share
drwxr-xr-x 2 root mysql 90 Apr 12 23:16 support-files
[root@n5 mysql]# mkdir -pv /data/mysql #创建mysql数据目录
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/mysql’
[root@n5 mysql]# chown -R mysql.mysql /data/mysql/ #mysql进程要进行写操作,修改权限
[root@n5 mysql]# ll /data
total 0
drwxr-xr-x 2 mysql mysql 6 Apr 12 23:28 mysql
[root@n5 mysql]# vim /etc/profile.d/mysql.sh #编写修改环境变量脚本
export PATH=/usr/local/mysql/bin:$PATH
[root@n5 mysql]# . /etc/profile.d/mysql.sh #读取环境变量
[root@n5 mysql]# mkdir etc
[root@n5 mysql]# mkdir logs
[root@n5 mysql]# chown -R mysql.mysql logs/ #更改日志目录权限
[root@n5 mysql]# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
2018-04-13T05:28:25.149583Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-13T05:28:25.948412Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-04-13T05:28:26.058553Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-13T05:28:26.121981Z 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: 7da0526b-3edb-11e8-a71c-000c2977a305.
2018-04-13T05:28:26.124459Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-04-13T05:28:26.127938Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@n5 mysql]# cp /etc/my.cnf etc/
[root@n5 mysql]# vim etc/my.cnf #修改mysql配置文件
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/logs/error.log
pid-file=/var/run/mysql/mysql.pid
!includedir /usr/local/mysql/etc/my.cnf.d
[root@n5 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@n5 mysql]# ll /etc/init.d/mysqld #确保有执行权限
-rwxr-xr-x 1 root root 10576 Apr 13 01:39 /etc/init.d/mysqld
[root@n5 mysql]# chkconfig --add mysqld
[root@n5 mysql]# mkdir etc/my.cnf.d
[root@n5 mysql]# touch logs/error.log #新建错误日志文件
[root@n5 mysql]# chown -R mysql.mysql logs/error.log #修改错误日志文件属主属组
[root@n5 mysql]# service mysql start #开启mysql服务
Redirecting to /bin/systemctl start mysql.service
[root@n5 mysql]# mysql #运行mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>