1. 创建mysql要安装目录
mkdir /data
2. 上传或下载mysql安装包(二进制)
[root@modue-200 ~]# mkdir /data/
[root@modue-200 data]# mv ~/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz ./
[root@modue-200 data]# tar xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
[root@modue-200 data]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql
[root@modue-200 data]# ll
total 626104
drwxr-xr-x. 9 root root 129 May 16 02:52 mysql
-rw-r--r--. 1 root root 641127384 Apr 3 08:37 mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
3. 修改环境变量
echo "export PATH=/data/mysql/bin:$PATH" >> /etc/profile
[root@modue-200 ~]# source /etc/profile
4. 创建mysql所需目录和用户,以及修改权限
[root@modue-200 ~]# id mysql
id: mysql: no such user
[root@modue-200 ~]# useradd -r -M -s /sbin/nologin mysql
[root@modue-200 ~]# mkdir /data/mysql/data -p
[root@modue-200 ~]# chown -R mysql.mysql /data
5. 初始化程序
[root@modue-200 ~]# /data/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
2019-05-15T19:01:21.199898Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-05-15T19:01:22.604720Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-05-15T19:01:22.824670Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-05-15T19:01:22.907597Z 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: d4d9e940-7743-11e9-bab7-000c292e3374.
2019-05-15T19:01:22.909114Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-05-15T19:01:22.910833Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
6. 启动mysql程序
6.1. sys-v 启动mysql(适用于CentOS6/7)
6.1.1. 准备脚本和配置文件
[root@modue-200 ~]# cp /data/mysql/support-files /etc/init.d
[root@modue-200 ~]# cat /etc/my.cnf
[mysqld]
user=mysql
basedir=/data/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=6
[mysql]
socket=/tmp/mysql.sock
[root@modue-200 ~]# service mysql.server start
Starting MySQL. SUCCESS!
6.2. systemcyl 启动
6.2.1. 准备启动脚本
[root@modue-200 ~]# cat /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@modue-200 ~]# systemctl start mysqld.service
[root@modue-200 ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2019-05-16 03:14:15 CST; 12s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 7429 (mysqld)
CGroup: /system.slice/mysqld.service
└─7429 /data/mysql/bin/mysqld --defaults-file=/etc/my.cnf
7. 登录mysql以及修改密码
[root@modue-200 ~]# mysql
mysql> exit
[root@modue-200 ~]# mysqladmin -u root -p password 123
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@modue-200 ~]# mysql -u root -p123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.20 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> ^DBye
[root@modue-200 ~]#
网友评论