Preface
Article Directory
This article describes the installation of Mysql way offline
installation environment: centos7
1.
Go to the official website to download the binary installation package. Address: https://dev.mysql.com/downloads/mysql/5.7.html#downloads
2. Create mysql user
[root@mysql-server ~]# useradd -r mysql -M -s /bin/false
3. Upload the downloaded package, unzip it, create a mysql installation directory, and give permission.
[root@localhost ~]# ls
mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# tar zxf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# mv /usr/local/mysql-5.7.32-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@localhost ~]# mkdir /usr/local/mysql/data
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql/
[root@localhost ~]# ll /usr/local/mysql/
总用量 260
drwxr-xr-x 2 mysql mysql 4096 12月 27 15:04 bin
drwxr-xr-x 2 mysql mysql 6 12月 27 15:06 data
drwxr-xr-x 2 mysql mysql 55 12月 27 15:04 docs
drwxr-xr-x 3 mysql mysql 4096 12月 27 15:04 include
drwxr-xr-x 5 mysql mysql 230 12月 27 15:04 lib
-rw-r--r-- 1 mysql mysql 247914 9月 23 20:00 LICENSE
drwxr-xr-x 4 mysql mysql 30 12月 27 15:04 man
-rw-r--r-- 1 mysql mysql 587 9月 23 20:00 README
drwxr-xr-x 28 mysql mysql 4096 12月 27 15:04 share
drwxr-xr-x 2 mysql mysql 90 12月 27 15:04 support-files
4. Initialize mysql
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#初始化用户和安装位置和数据存放位置
2020-12-27T07:08:58.946572Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-12-27T07:08:59.674990Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-12-27T07:08:59.756715Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-12-27T07:08:59.821983Z 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: 6488a347-4812-11eb-9425-000c2907d01b.
2020-12-27T07:08:59.824487Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-12-27T07:09:00.478438Z 0 [Warning] CA certificate ca.pem is self signed.
2020-12-27T07:09:00.650741Z 1 [Note] A temporary password is generated for root@localhost: I#shqhH+(6qk
5. Configure mysql configuration file under etc
vim /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
6. Configure environment variables for easy management
vim /etc/profile.d/mysql.sh
最后一行加上这个
export PATH=/usr/local/mysql/bin:$PATH
保存刷新
source /etc/profile.d/mysql.sh
- Add startup script and change password
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
vim /etc/init.d/mysqld
basedir=/usr/local/mysql #第46行 补全安装目录
datadir=/usr/local/mysql/data #第47行 补全数据所在目录
/etc/init.d/mysqld start #刷新
mysqladmin -u root -p'初始密码' password '新密码' #新密码必须包含大小写英文、数字、特殊符号。
#登陆mysql
mysq -uroot -p'新密码'