Linux下使用rpm包安装MySQL数据库

[root@Hadoop102 ~]# df - h
df: "-": 没有那个文件或目录
df: "h": 没有那个文件或目录
[root@Hadoop102 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   45G  6.4G   39G   15% /
devtmpfs                 977M     0  977M    0% /dev
tmpfs                    993M     0  993M    0% /dev/shm
tmpfs                    993M  9.1M  984M    1% /run
tmpfs                    993M     0  993M    0% /sys/fs/cgroup
/dev/sda1                976M  131M  778M   15% /boot
tmpfs                    199M   12K  199M    1% /run/user/42
tmpfs                    199M     0  199M    0% /run/user/1000

#--切换至root用户执行,否则rpm安装没有权限
[root@Hadoop102 ~]# su - root
上一次登录:四 4月 21 23:39:44 CST 2022pts/1 上

#--查看是否安装mysql服务
[root@Hadoop102 ~]# rpm -qa | grep -i mysql
[root@Hadoop102 ~]# rmp -ev --nodeps MySQL-server-5.6.24-1.el7.x86_64
bash: rmp: 未找到命令...
相似命令是: 'rpm'

#--卸载安装的旧mysql服务
[root@Hadoop102 ~]# rpm -ev --nodeps MySQL-server-5.6.24-1.el7.x86_64  
错误:未安装软件包 MySQL-server-5.6.24-1.el7.x86_64 
[root@Hadoop102 ~]# rpm -ev --nodeps MySQL-client-5.6.24-1.el7.x86_64
错误:未安装软件包 MySQL-client-5.6.24-1.el7.x86_64 

#--进入mysql安装包rpm包目录
[root@Hadoop102 ~]# cd /opt/mysql/
[root@Hadoop102 mysql]# ll
总用量 78620
-rwxrwxr-x. 1 mysql mysql 19904612 4月  21 22:36 MySQL-client-5.6.24-1.el7.x86_64.rpm
-rwxrwxr-x. 1 mysql mysql 60596392 4月  21 22:37 MySQL-server-5.6.24-1.el7.x86_64.rpm

#--安装perl-Data-Dumper包,否则安装Oracle时会报错,抛出需要安装Data-Dumper
[root@Hadoop102 mysql]# yum install -y perl-Data-Dumper
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * epel: my.mirrors.thegigabit.com
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.ustc.edu.cn
软件包 perl-Data-Dumper-2.145-3.el7.x86_64 已安装并且是最新版本
无须任何处理

#--rpm安装mysql
[root@Hadoop102 mysql]# rmp -ivh MySQL-server-5.6.24-1.el7.x86_64.rpm
bash: rmp: 未找到命令...
相似命令是: 'rpm'
[root@Hadoop102 mysql]# rpm -ivh MySQL-server-5.6.24-1.el7.x86_64.rpm  
准备中...                          ################################# [100%]
正在升级/安装...
   1:MySQL-server-5.6.24-1.el7        ################################# [100%]
2022-04-21 23:47:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-04-21 23:47:24 0 [Note] /usr/sbin/mysqld (mysqld 5.6.24) starting as process 4722 ...
2022-04-21 23:47:24 4722 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-04-21 23:47:24 4722 [Note] InnoDB: The InnoDB memory heap is disabled
2022-04-21 23:47:24 4722 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-04-21 23:47:24 4722 [Note] InnoDB: Memory barrier is not used
2022-04-21 23:47:24 4722 [Note] InnoDB: Compressed tables use zlib 1.2.3
2022-04-21 23:47:24 4722 [Note] InnoDB: Using Linux native AIO
2022-04-21 23:47:24 4722 [Note] InnoDB: Using CPU crc32 instructions
2022-04-21 23:47:24 4722 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2022-04-21 23:47:24 4722 [Note] InnoDB: Completed initialization of buffer pool
2022-04-21 23:47:24 4722 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2022-04-21 23:47:24 4722 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2022-04-21 23:47:24 4722 [Note] InnoDB: Database physically writes the file full: wait...
2022-04-21 23:47:24 4722 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2022-04-21 23:47:24 4722 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2022-04-21 23:47:24 4722 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2022-04-21 23:47:24 4722 [Warning] InnoDB: New log files created, LSN=45781
2022-04-21 23:47:24 4722 [Note] InnoDB: Doublewrite buffer not found: creating new
2022-04-21 23:47:24 4722 [Note] InnoDB: Doublewrite buffer created
2022-04-21 23:47:24 4722 [Note] InnoDB: 128 rollback segment(s) are active.
2022-04-21 23:47:24 4722 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-04-21 23:47:24 4722 [Note] InnoDB: Foreign key constraint system tables created
2022-04-21 23:47:24 4722 [Note] InnoDB: Creating tablespace and datafile system tables.
2022-04-21 23:47:24 4722 [Note] InnoDB: Tablespace and datafile system tables created.
2022-04-21 23:47:24 4722 [Note] InnoDB: Waiting for purge to start
2022-04-21 23:47:24 4722 [Note] InnoDB: 5.6.24 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2022-04-21 23:47:25 4722 [Note] Binlog end
2022-04-21 23:47:25 4722 [Note] InnoDB: FTS optimize thread exiting.
2022-04-21 23:47:25 4722 [Note] InnoDB: Starting shutdown...
2022-04-21 23:47:26 4722 [Note] InnoDB: Shutdown completed; log sequence number 1625977


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

#--此处为临时mysql root用户密码查看位置说明(首次连接/更改密码时需使用临时密码)
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.

[root@Hadoop102 mysql]# ll
总用量 78620
-rwxrwxr-x. 1 mysql mysql 19904612 4月  21 22:36 MySQL-client-5.6.24-1.el7.x86_64.rpm
-rwxrwxr-x. 1 mysql mysql 60596392 4月  21 22:37 MySQL-server-5.6.24-1.el7.x86_64.rpm

#--安装mysql客户端
[root@Hadoop102 mysql]# rpm -ivh MySQL-client-5.6.24-1.el7.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:MySQL-client-5.6.24-1.el7        ################################# [100%]
 
#更改mysql数据库root用户登录密码
[root@Hadoop102 mysql]# mysqladmin -u root -p password '123456'
Enter password: 
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
[root@Hadoop102 mysql]# cat /root/.mysql_secret
# The random password set for the root user at Thu Apr 21 23:47:24 2022 (local time): VXDgZOQ1PMjkDfj1

[root@Hadoop102 mysql]# service status mysql
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
[root@Hadoop102 mysql]# systemctl status mysql
● mysql.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysql; bad; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)

4月 21 23:18:24 Hadoop102 systemd[1]: Starting LSB: start and stop MySQL...
4月 21 23:18:24 Hadoop102 mysql[3702]: Starting MySQL SUCCESS!
4月 21 23:18:24 Hadoop102 systemd[1]: Started LSB: start and stop MySQL.
4月 21 23:20:57 Hadoop102 systemd[1]: Stopping LSB: start and stop MySQL...
4月 21 23:20:59 Hadoop102 mysql[3856]: Shutting down MySQL.. SUCCESS!
4月 21 23:20:59 Hadoop102 systemd[1]: Stopped LSB: start and stop MySQL.

'#查看mysql服务状态'
[root@Hadoop102 mysql]# service mysql status
 ERROR! MySQL is not running
 
 '启动mysql服务'
[root@Hadoop102 mysql]# service mysql start
Starting MySQL. SUCCESS! 

'更改mysql数据库root用户登录密码'
[root@Hadoop102 mysql]# mysqladmin -u root -p password '123456'
Enter password: 
Warning: Using a password on the command line interface can be insecure.

'登录mysql数据库'
[root@Hadoop102 mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye
[root@Hadoop102 mysql]# 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.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> select * from user;
ERROR 1046 (3D000): No database selected
mysql> select * from users;
ERROR 1046 (3D000): No database selected
mysql> exit
Bye
[root@Hadoop102 mysql]# mysql -u root -p123456
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 4
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> show user
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user' at line 1
mysql> show users;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'users' at line 1

'切换至mysql数据库'
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> select * from user;
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-----------------------+------------------+
| Host      | User | Password                                  | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin                | authentication_string | password_expired |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-----------------------+------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password |                       | N                |
| hadoop102 | root | *3C6E82379D36AADDF7F77A669F853AE320678C86 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password |                       | Y                |
| 127.0.0.1 | root | *3C6E82379D36AADDF7F77A669F853AE320678C86 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password |                       | Y                |
| ::1       | root | *3C6E82379D36AADDF7F77A669F853AE320678C86 | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password |                       | Y                |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-----------------------+------------------+
4 rows in set (0.00 sec)

mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | hadoop102 | *3C6E82379D36AADDF7F77A669F853AE320678C86 |
| root | 127.0.0.1 | *3C6E82379D36AADDF7F77A669F853AE320678C86 |
| root | ::1       | *3C6E82379D36AADDF7F77A669F853AE320678C86 |
+------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)


'将连接mysql数据库的主机修改为任意主机,以防其它客户端无法连接'
mysql> update user set host ='%' where host ='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | %         | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | hadoop102 | *3C6E82379D36AADDF7F77A669F853AE320678C86 |
| root | 127.0.0.1 | *3C6E82379D36AADDF7F77A669F853AE320678C86 |
| root | ::1       | *3C6E82379D36AADDF7F77A669F853AE320678C86 |
+------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)


'删除其它用户连接主机数据,只保留任意主机那一条数据'
mysql> delete from user where host in('hadoop102','127.0.0.1','::1');
Query OK, 3 rows affected (0.00 sec)

mysql> select user,host,password from user;
+------+------+-------------------------------------------+
| user | host | password                                  |
+------+------+-------------------------------------------+
| root | %    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+------+-------------------------------------------+
1 row in set (0.00 sec)

mysql> exit
Bye
[root@Hadoop102 mysql]# mysql -uroot -p123456
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 6
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye
[root@Hadoop102 mysql]# echo mysql 安装完成
mysql 安装完成
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值