[root@promote home]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz [root@promote home]# ls
mysql-5.7.26-linux-glibc2.12-x86_64 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@promote home]# mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql-5.7.26[root@promote home]# ls
mysql-5.7.26 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@promote home]# cd mysql-5.7.26[root@promote mysql-5.7.26]# ls
bin COPYING docs include lib man README share support-files
添加用户组
[root@promote mysql-5.7.26]# groups mysql
groups: mysql: no such user
[root@promote mysql-5.7.26]# groupadd mysql[root@promote mysql-5.7.26]# useradd -r -g mysql mysql[root@promote mysql-5.7.26]# groups mysql
mysql : mysql
配置mysql配置文件/etc/my.cnf
[root@promote mysql-5.7.26]# cat /etc/my.cnf | grep -v '#'[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
[root@promote mysql-5.7.26]# mkdir data[root@promote mysql-5.7.26]# ll
总用量 36
drwxr-xr-x. 2 root root 4096 11月 15 14:14 bin
-rw-r--r--. 1 7161 31415 17987 4月 13 2019 COPYING
drwxr-xr-x. 2 root root 6 11月 15 14:22 data
drwxr-xr-x. 2 root root 55 11月 15 14:14 docs
drwxr-xr-x. 3 root root 4096 11月 15 14:13 include
drwxr-xr-x. 5 root root 230 11月 15 14:14 lib
drwxr-xr-x. 4 root root 30 11月 15 14:14 man
-rw-r--r--. 1 7161 31415 2478 4月 13 2019 README
drwxr-xr-x. 28 root root 4096 11月 15 14:14 share
drwxr-xr-x. 2 root root 90 11月 15 14:14 support-files
[root@promote mysql-5.7.26]# chown -R mysql:mysql ./[root@promote mysql-5.7.26]# ll
总用量 36
drwxr-xr-x. 2 mysql mysql 4096 11月 15 14:14 bin
-rw-r--r--. 1 mysql mysql 17987 4月 13 2019 COPYING
drwxr-xr-x. 2 mysql mysql 6 11月 15 14:22 data
drwxr-xr-x. 2 mysql mysql 55 11月 15 14:14 docs
drwxr-xr-x. 3 mysql mysql 4096 11月 15 14:13 include
drwxr-xr-x. 5 mysql mysql 230 11月 15 14:14 lib
drwxr-xr-x. 4 mysql mysql 30 11月 15 14:14 man
-rw-r--r--. 1 mysql mysql 2478 4月 13 2019 README
drwxr-xr-x. 28 mysql mysql 4096 11月 15 14:14 share
drwxr-xr-x. 2 mysql mysql 90 11月 15 14:14 support-files
[root@promote mysql-5.7.26]# pwd/home/mysql-5.7.26
[root@promote mysql-5.7.26]# cd data/[root@promote data]# pwd/home/mysql-5.7.26/data[root@promote data]# vi /etc/my.cnf[root@promote data]# cat /etc/my.cnf | grep -v '#'[mysqld]
basedir=/home/mysql-5.7.26
datadir=/home/mysql-5.7.26/data
port=3306
default-character-set=utf8
character-set-server=utf8
skip-name-resolve
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=100M
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
[root@promote lib]# cd /home/mysql-5.7.26/bin/[root@promote bin]# ls
innochecksum my_print_defaults mysql_config mysqldump mysqlpump mysql_tzinfo_to_sql resolve_stack_dump
lz4_decompress mysql mysql_config_editor mysqldumpslow mysql_secure_installation mysql_upgrade zlib_decompress
myisamchk mysqladmin mysqld mysql_embedded mysqlshow mysqlxtest
myisam_ftdump mysqlbinlog mysqld-debug mysqlimport mysqlslap perror
myisamlog mysqlcheck mysqld_multi mysql_install_db mysql_ssl_rsa_setup replace
myisampack mysql_client_test_embedded mysqld_safe mysql_plugin mysqltest_embedded resolveip
[root@promote bin]# ./mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.26 --datadir=/home/mysql-5.7.26/data
2020-11-15T06:34:25.526824Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-15T06:34:25.951996Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-11-15T06:34:26.329336Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-11-15T06:34:26.404586Z 0 [ERROR] unknown variable 'default-character-set=utf8'
2020-11-15T06:34:26.404604Z 0 [ERROR] Aborting
[root@promote bin]# vi /etc/my.cnf[root@promote bin]# cat /etc/my.cnf | grep -v '#'[mysqld]
basedir=/home/mysql-5.7.26
datadir=/home/mysql-5.7.26/data
port=3306
skip-name-resolve
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=100M
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
[root@promote bin]# ./mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.26 --datadir=/home/mysql-5.7.26/data
2020-11-15T06:37:06.366230Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-15T06:37:06.368811Z 0 [ERROR]--initialize specified but the data directory has files in it. Aborting.
2020-11-15T06:37:06.368835Z 0 [ERROR] Aborting
[root@promote home]# cd /var/lib/mysql/[root@promote mysql]# ls[root@promote mysql]# cd /home/mysql-5.7.26/data/[root@promote data]# ls
ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1
[root@promote data]# rm -rf *[root@promote data]# ls[root@promote data]# cd ../bin/[root@promote bin]# ./mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.26 --datadir=/home/mysql-5.7.26/data
2020-11-15T06:42:00.328438Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-15T06:42:00.727354Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-11-15T06:42:00.807571Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-11-15T06:42:00.869241Z 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: aa368e3a-270d-11eb-8dd6-000c29eed173.
2020-11-15T06:42:00.871305Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-11-15T06:42:00.872700Z 1 [Note] A temporary password is generated for root@localhost: ol_ott0k&j-C
[root@promote run]# service mysql start
Starting MySQL.. SUCCESS![root@promote run]# service mysql status
SUCCESS! MySQL running (18553)
设置软连接 全局service mysql xxx 命令启动
[root@promote run]# ln -s /var/lib/mysql/mysql.sock /tmp/[root@promote run]# ln -s /home/mysql-5.7.26/bin/mysql /usr/bin/[root@promote run]# service mysql
Usage: mysql {start|stop|restart|reload|force-reload|status}[ MySQL server options ][root@promote run]# service mysql status
SUCCESS! MySQL running (18553)
登录并修改密码
root@promote run]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26
Copyright (c) 2000, 2019, 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> alter user 'root'@'localhost' identified by 'root'-> \g
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user from mysql.user
-> \g
+-----------+---------------+| host | user |+-----------+---------------+| localhost | mysql.session || localhost | mysql.sys || localhost | root |+-----------+---------------+
3 rows in set(0.00 sec)
mysql> flush privileges
-> \g
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@promote run]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='%' where user = 'root'-> \g
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges
-> \g
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user from mysql.user
-> \g
+-----------+---------------+| host | user |+-----------+---------------+|%| root || localhost | mysql.session || localhost | mysql.sys |+-----------+---------------+
3 rows in set(0.00 sec)
mysql> exit
Bye