Linux下基于RPM BUNDLE包安装MySQL

时间:2021-08-06 00:41:39
--Linux下基于RPM BUNDLE包安装MySQL


下载地址:http://dev.mysql.com/downloads/mysql/


[root@ocm2 ~]# ls mysql-5.7.17-1.el5.i686.rpm-bundle.tar 
mysql-5.7.17-1.el5.i686.rpm-bundle.tar
[root@ocm2 ~]# mkdir -pv /usr/src/mysql
mkdir: created directory '/usr/src/mysql'
You have new mail in /var/spool/mail/root
[root@ocm2 ~]# tar xvf mysql-5.7.17-1.el5.i686.rpm-bundle.tar -C /usr/src/mysql/
mysql-community-libs-5.7.17-1.el5.i686.rpm
mysql-community-server-5.7.17-1.el5.i686.rpm
mysql-community-embedded-5.7.17-1.el5.i686.rpm
mysql-5.7.17-1.el5.i686.rpm
mysql-community-common-5.7.17-1.el5.i686.rpm
mysql-community-test-5.7.17-1.el5.i686.rpm
mysql-community-devel-5.7.17-1.el5.i686.rpm
mysql-community-embedded-devel-5.7.17-1.el5.i686.rpm
mysql-community-client-5.7.17-1.el5.i686.rpm
mysql-community-libs-compat-5.7.17-1.el5.i686.rpm
[root@ocm2 ~]# cd /usr/src/mysql/
[root@ocm2 mysql]# ls
mysql-5.7.17-1.el5.i686.rpm
mysql-community-client-5.7.17-1.el5.i686.rpm --客户端
mysql-community-common-5.7.17-1.el5.i686.rpm
mysql-community-devel-5.7.17-1.el5.i686.rpm --mysql库文件头文件
mysql-community-embedded-5.7.17-1.el5.i686.rpm
mysql-community-embedded-devel-5.7.17-1.el5.i686.rpm
mysql-community-libs-5.7.17-1.el5.i686.rpm
mysql-community-libs-compat-5.7.17-1.el5.i686.rpm
mysql-community-server-5.7.17-1.el5.i686.rpm --服务器
mysql-community-test-5.7.17-1.el5.i686.rpm

--安装方式可以采用rpm或者yum install,rpm方式缺少的关联包需要手动安装
--几个包都存在相互依赖的关系,所用使用--nodeps参数忽略依赖关系
[root@ocm2 mysql]# rpm -ivh mysql-community-server-5.7.17-1.el5.i686.rpm --nodeps
warning: mysql-community-server-5.7.17-1.el5.i686.rpm: Header V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing... ########################################### [100%]
1:mysql-community-server ########################################### [100%]
[root@ocm2 mysql]# rpm -ivh mysql-community-client-5.7.17-1.el5.i686.rpm --nodeps
warning: mysql-community-client-5.7.17-1.el5.i686.rpm: Header V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing... ########################################### [100%]
1:mysql-community-client ########################################### [100%]
[root@ocm2 mysql]# rpm -ivh mysql-community-libs-5.7.17-1.el5.i686.rpm --nodeps
warning: mysql-community-libs-5.7.17-1.el5.i686.rpm: Header V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing... ########################################### [100%]
1:mysql-community-libs ########################################### [100%]
[root@ocm2 mysql]# rpm -ivh mysql-community-libs-compat-5.7.17-1.el5.i686.rpm --nodeps
warning: mysql-community-libs-compat-5.7.17-1.el5.i686.rpm: Header V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing... ########################################### [100%]
1:mysql-community-libs-co########################################### [100%]
[root@ocm2 mysql]# rpm -ivh mysql-community-common-5.7.17-1.el5.i686.rpm --nodeps
warning: mysql-community-common-5.7.17-1.el5.i686.rpm: Header V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [100%]
[root@ocm2 mysql]# /etc/init.d/mysqld start
Initializing MySQL database: [ OK ]
Installing validate password plugin: [ OK ]
Starting mysqld: [ OK ]

对于Mysql 5.7.6以后的5.7系列版本,Mysql使用mysqld --initialize或mysqld --initialize-insecure命令来初始化数据库,后者可以不生成随机密码。
但是安装Mysql时默认使用的是前一个命令,这个命令也会生成一个随机密码。改密码保存在了Mysql的日志文件中。

[root@ocm2 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log --找到日志路径
pid-file=/var/run/mysqld/mysqld.pid
[root@ocm2 ~]# cat /var/log/mysqld.log | grep password --查到密码为PCbu?SNEx8zl
2016-12-25T04:12:33.648941Z 1 [Note] A temporary password is generated for root@localhost: PCbu?SNEx8zl
2016-12-25T04:12:41.541468Z 0 [Note] Execution of init_file '/var/lib/mysql/install-validate-password-plugin.XXXXXX.sql' started.
2016-12-25T04:12:41.542356Z 0 [Note] Execution of init_file '/var/lib/mysql/install-validate-password-plugin.XXXXXX.sql' ended.
2016-12-25T04:12:43.371977Z 0 [Note] Shutting down plugin 'sha256_password'
2016-12-25T04:12:43.371981Z 0 [Note] Shutting down plugin 'mysql_native_password'
2016-12-25T04:12:45.952514Z 3 [Note] Access denied for user 'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)
2016-12-25T04:30:16.108857Z 4 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2016-12-25T04:30:20.728257Z 5 [Note] Access denied for user 'root'@'localhost' (using password: YES)

[root@ocm2 ~]# /usr/bin/mysql_secure_installation --安装完mysql后执行自带的安全设置

Securing the MySQL server deployment.

Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y --移除匿名用户
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y --不允许远程连接
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y --移除测试数据库
- Dropping test database...
Success.

- Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y --重读授权表使前面修改生效
Success.

All done!

[root@ocm2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> create database luo
-> ;
Query OK, 1 row affected (0.00 sec)

mysql> use luo
Database changed

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| luo |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

至此安装完成。