Red Hat 4.8.5-16 安装 Mysql 5.6.36

387 阅读7分钟

Red Hat 4.8.5-16 Mysql 5.6.36

1 检查、删除已安装MySQL

# rpm 方式
[root@vultr ~]# rpm -qa | grep -i mysql
1) 如果有rpm包安装的MySQL,使用以下命令删除:
[root@vultr ~]# rpm -e --nodeps 包名
2) 查找之前老版本MySQL的目录,文件并且删除
[root@vultr ~]# find / -name mysql
[root@vultr ~]# rm -rf 目录
[root@vultr ~]# rm -rf /etc/my.cnf   # 需要手动删除my.cnf文件
3) 再次查找机器是否安装了MySQL
[root@vultr ~]# rpm -qa | grep -i mysql

2 检查、删除冲突软件

# mariadb
rpm -qa|grep mariadb
rpm -e --nodeps 

3 检查、关闭进程

[root@linux ~]# ps -ef|grep mysql
root     27147 22596  0 14:47 pts/5    00:00:00 grep --color=auto mysqld
root     35193     1  0 May30 ?        00:01:29 bin/mysqld --user=root

4 安装

[root@linux /]# tar -xvf MySQL-5.6.36-1.linux_glibc2.5.x86_64.rpm-bundle.tar
MySQL-devel-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-server-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-compat-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-client-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-test-5.6.36-1.linux_glibc2.5.x86_64.rpm
MySQL-embedded-5.6.36-1.linux_glibc2.5.x86_64.rpm
[root@linux /]# rpm -ivh MySQL*.rpm
warning: MySQL-client-5.6.36-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-devel-5.6.36-1.linux_glibc2################################# [ 14%]
   2:MySQL-client-5.6.36-1.linux_glibc################################# [ 29%]
   3:MySQL-test-5.6.36-1.linux_glibc2.################################# [ 43%]
   4:MySQL-embedded-5.6.36-1.linux_gli################################# [ 57%]
   5:MySQL-shared-compat-5.6.36-1.linu################################# [ 71%]
   6:MySQL-shared-5.6.36-1.linux_glibc################################# [ 86%]
   7:MySQL-server-5.6.36-1.linux_glibc################################# [100%]
2022-05-31 15:58:18 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-05-31 15:58:18 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2022-05-31 15:58:18 0 [Note] /usr/sbin/mysqld (mysqld 5.6.36) starting as process 32440 ...
2022-05-31 15:58:18 32440 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-05-31 15:58:18 32440 [Note] InnoDB: The InnoDB memory heap is disabled
2022-05-31 15:58:18 32440 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-05-31 15:58:18 32440 [Note] InnoDB: Memory barrier is not used
2022-05-31 15:58:18 32440 [Note] InnoDB: Compressed tables use zlib 1.2.3
2022-05-31 15:58:18 32440 [Note] InnoDB: Using Linux native AIO
2022-05-31 15:58:18 32440 [Note] InnoDB: Using CPU crc32 instructions
2022-05-31 15:58:18 32440 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2022-05-31 15:58:18 32440 [Note] InnoDB: Completed initialization of buffer pool
2022-05-31 15:58:18 32440 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2022-05-31 15:58:18 32440 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2022-05-31 15:58:18 32440 [Note] InnoDB: Database physically writes the file full: wait...
2022-05-31 15:58:18 32440 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2022-05-31 15:58:18 32440 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2022-05-31 15:58:19 32440 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2022-05-31 15:58:19 32440 [Warning] InnoDB: New log files created, LSN=45781
2022-05-31 15:58:19 32440 [Note] InnoDB: Doublewrite buffer not found: creating new
2022-05-31 15:58:19 32440 [Note] InnoDB: Doublewrite buffer created
2022-05-31 15:58:19 32440 [Note] InnoDB: 128 rollback segment(s) are active.
2022-05-31 15:58:19 32440 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-05-31 15:58:19 32440 [Note] InnoDB: Foreign key constraint system tables created
2022-05-31 15:58:19 32440 [Note] InnoDB: Creating tablespace and datafile system tables.
2022-05-31 15:58:19 32440 [Note] InnoDB: Tablespace and datafile system tables created.
2022-05-31 15:58:19 32440 [Note] InnoDB: Waiting for purge to start
2022-05-31 15:58:19 32440 [Note] InnoDB: 5.6.36 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2022-05-31 15:58:20 32440 [Note] Binlog end
2022-05-31 15:58:20 32440 [Note] InnoDB: FTS optimize thread exiting.
2022-05-31 15:58:20 32440 [Note] InnoDB: Starting shutdown...
2022-05-31 15:58:22 32440 [Note] InnoDB: Shutdown completed; log sequence number 1625977


2022-05-31 15:58:22 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-05-31 15:58:22 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2022-05-31 15:58:22 0 [Note] /usr/sbin/mysqld (mysqld 5.6.36) starting as process 32495 ...
2022-05-31 15:58:22 32495 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-05-31 15:58:22 32495 [Note] InnoDB: The InnoDB memory heap is disabled
2022-05-31 15:58:22 32495 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-05-31 15:58:22 32495 [Note] InnoDB: Memory barrier is not used
2022-05-31 15:58:22 32495 [Note] InnoDB: Compressed tables use zlib 1.2.3
2022-05-31 15:58:22 32495 [Note] InnoDB: Using Linux native AIO
2022-05-31 15:58:22 32495 [Note] InnoDB: Using CPU crc32 instructions
2022-05-31 15:58:22 32495 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2022-05-31 15:58:22 32495 [Note] InnoDB: Completed initialization of buffer pool
2022-05-31 15:58:22 32495 [Note] InnoDB: Highest supported file format is Barracuda.
2022-05-31 15:58:22 32495 [Note] InnoDB: 128 rollback segment(s) are active.
2022-05-31 15:58:22 32495 [Note] InnoDB: Waiting for purge to start
2022-05-31 15:58:22 32495 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2022-05-31 15:58:22 32495 [Note] Binlog end
2022-05-31 15:58:22 32495 [Note] InnoDB: FTS optimize thread exiting.
2022-05-31 15:58:22 32495 [Note] InnoDB: Starting shutdown...
2022-05-31 15:58:24 32495 [Note] InnoDB: Shutdown completed; log sequence number 1625987




A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file /usr/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/my-new.cnf,
please compare it with your file and take the changes you need.


5 服务状态

# 服务状态
service mysql start
service mysql status
service mysql stop
service mysql restart
​

6 设置密码权限

# 查看初始密码
[root@linux /]# cat /root/.mysql_secret | grep password
# The random password set for the root user at Tue May 31 15:17:22 2022 (local time): T2tZvqCvajQwhm3A
# 设置密码为123456
mysql -uroot –pT2tZvqCvajQwhm3A
SET PASSWORD = PASSWORD('123456');    
​
# 远程登陆用户设置 
mysql -uroot -p123456
use mysql;
select host,user,password from user;
update user set password=password('123456') where user='root';
update user set host='%' where user='root' and host='localhost';
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;

7 附录

# 通过rpm安装的mysql找不到my.cnf解决方法
cd /usr/share/mysql
cp my-default.cnf /etc/my.cnf
# 添加忽略大小写配置
lower_case_table_names=1
​
​
# 相关路径
a.数据库目录: /var/lib/mysql/
b.配置文件: /usr/share/mysql
c.相关命令: /usr/bin
d.启动脚本: /etc/rc.d/init.d/
​
​
# 导出数据文件
mysqldump -uroot -h127.0.0.1 -p123456 -P3358 db_name --single-transaction=true --skip-add-locks --skip-add-drop-table --skip-disable-keys > sqlFile.sql
​
# 导入数据
进入mysql
source sqlFile;
​
​
# 开启慢sql
set global slow_query_log='ON';
show variables like "slow_query_log";
show variables like '%slow%';
​
​
mysql> show variables like '%slow%';
+---------------------------+--------------------------------------------+
| Variable_name             | Value                                      |
+---------------------------+--------------------------------------------+
| log_slow_admin_statements | OFF                                        |
| log_slow_slave_statements | OFF                                        |
| slow_launch_time          | 2                                          |
| slow_query_log            | ON                                         |
| slow_query_log_file       | /var/lib/mysql/linux-slow.log |
+---------------------------+--------------------------------------------+
5 rows in set (0.01 sec)
​
​

8 参考

RedHat下RPM方式安装MySQL 5.7