之前安装mysql时候比较慢,以下是加速版的
上传安装包mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
1、确保系统中有依赖的libaio软件,使用如下命令
[root@localhost ~]# yum -y install libaio
[root@localhost ~]# rpm -q libaio
libaio-0.3.109-13.el7.x86_64
2、使用wget命令下载mysql-5.7.24软件包
3、将mysql安装包解压到指定目录,命令如下
[root@localhost ~]# tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ //估计用时有点慢
4、进入到/usr/local/目录
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin
etc
games
include
lib
lib64
libexec
mysql-5.7.24-linux-glibc2.12-x86_64
nginx
sbin
share
src
5、为mysql安装目录创建软连接
[root@localhost local]# ln -s mysql-5.7.24-linux-glibc2.12-x86_64/ mysql
也可以用
[root@localhost local]# mv mysql-5.7.24-linux-glibc2.12-x86_64/ mysql
6、添加mysql用户和组
[root@localhost local]# useradd -M -s /sbin/nologin mysql
7、修改当前目录拥有者为新建的mysql用户,命令如下
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql/
8、初始化mysql数据库(建立默认的库和表),命令如下
[root@localhost local]# cd /usr/local/mysql/
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
porary password is generated for root@localhost: hr%5qe:XrjiI //记下随机产生的密码
9、修改mysql配置文件,命令如下
[root@localhost ~]# vim /etc/my.cnf
2 datadir=/usr/local/mysql/data
3 socket=/tmp/mysql.sock
12 log-error=/usr/local/mysql/data/mysql.log
13 pid-file=/usr/local/mysql/data/mysql.pid
保存退出
10、将mysql服务添加到系统服务中,命令如下
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chmod +x /etc/init.d/mysqld
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# systemctl start mysqld
tcp6 0 0 :::3306 :::* LISTEN 48952/mysqld
11、将mysql命令添加到系统命令执行路径中,便于使用
[root@localhost ~]# ln -s /usr/local/mysql/bin/mysql /bin/
12、使用随机密码登录mysql数据库,命令如下
[root@localhost ~]# mysql -uroot -p'hr%5qe:XrjiI'
。。。。。
Bye
13、设置mysql管理用户root的新密码
[root@localhost ~]# ln -sf /usr/local/mysql/bin/* /bin/
[root@localhost ~]# mysqladmin -uroot -p'hr%5qe:XrjiI' password 123456
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@localhost ~]# mysql -uroot -p123456
破译密码:
在生产环境中,要保证在业务不繁忙的情况下进行破译,因为破译时需要进行关闭数据库
[root@localhost ~]# systemctl stop mysqld
[root@localhost ~]# ps aux |grep mysqld
root 49128 0.0 0.0 112676 984 pts/2 S+ 21:43 0:00 grep --color=auto mysqld //确保没有与之相关的进程
[root@localhost ~]# mysqld_safe --skip-grant-tables &
[1] 49145
[root@localhost ~]# 2019-11-20T13:44:53.569922Z mysqld_safe Logging to '/usr/local/mysql/data/mysql.log'.
2019-11-20T13:44:53.588675Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data ///放到后台去启动
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.24 MySQL Community Server (GPL)
affiliates. Other names may be trademarks of their respective
owners.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | NO | | mysql_native_password | |
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
45 rows in set (0.00 sec)
| user | authentication_string |
+---------------+-------------------------------------------+
| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-------------------------------------------+
3 rows in set (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
Query OK, 0 rows affected (0.00 sec)
Bye
root 9993 0.0 0.0 113264 1608 pts/2 S 10:19 0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql 10135 0.1 9.2 1119996 172652 pts/2 Sl 10:19 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --skip-grant-tables --log-error=/usr/local/mysql/data/mysql.log --pid-file=/usr/local/mysql/data/mysql.pid --socket=/tmp/mysql.sock
root 10245 0.0 0.0 112676 984 pts/2 R+ 10:26 0:00 grep --color=auto mysqld
[root@nginx ~]# kill -9 9993
[root@nginx ~]# kill -9 10135
[1]+ 已杀死 mysqld_safe --skip-grant-tables
[root@nginx ~]# ps aux|grep mysqld
root 10255 0.0 0.0 112676 984 pts/2 R+ 10:27 0:00 grep --color=auto mysqld
[root@nginx ~]# mysql -uroot -p'123456'
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 2
Server version: 5.7.24 MySQL Community Server (GPL)
affiliates. Other names may be trademarks of their respective
owners.
Bye
[root@nginx ~]#