mysql管理工具mysqladmin的使用

1. 初始化密码

mysqladmin -uroot -p'password' password 'new-password' 
[root@controller3 ~]# yum -y install mariadb
......
[root@controller3 ~]# systemctl start mariadb
[root@controller3 ~]# mysqladmin -uroot password '123456'   #mariadb默认无初始密码,mysql可能需要去/var/log/mysqld.log查找初始密码
[root@controller3 ~]# mysql -uroot 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@controller3 ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 27
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye
[root@controller3 ~]# 

2. 创建,查看,删除数据库

mysqladmin -uroot -p create test_db
mysqlshow -uroot -p
mysqladmin -uroot -p drop test_db -f
[root@test234 ~]# mysqladmin -uroot -p create test_db
Enter password: 
[root@test234 ~]# mysqlshow -uroot -p 
Enter password: 
+--------------------+
|     Databases      |
+--------------------+
| django             |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test_db            |
+--------------------+
[root@test234 ~]# mysqladmin -uroot -p drop test_db
Enter password: 
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'test_db' database [y/N] yes
Database "test_db" dropped
[root@test234 ~]# mysqlshow -uroot -p 
Enter password: 
+--------------------+
|     Databases      |
+--------------------+
| django             |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
[root@test234 ~]# 

[root@test234 ~]# mysqladmin -uroot -p create test_db
Enter password:
[root@test234 ~]# mysqlshow -uroot -p
Enter password:
+--------------------+
| Databases |
+--------------------+
| django |
| information_schema |
| mysql |
| performance_schema |
| sys |
| test_db |
+--------------------+
[root@test234 ~]# mysqladmin -uroot -p -f drop test_db
Enter password:
Database "test_db" dropped
[root@test234 ~]# mysqladmin -uroot -p create test_db
Enter password:
[root@test234 ~]# mysqladmin -uroot -p drop test_db --force
Enter password:
Database "test_db" dropped

mysqlshow -uroot -p database_name

[root@test234 ~]# mysqlshow -uroot -p django
Enter password: 
Database: django
+----------------------------+
|           Tables           |
+----------------------------+
| auth_group                 |
| auth_group_permissions     |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| django_admin_log           |
| django_content_type        |
| django_migrations          |
| django_session             |
+----------------------------+

[root@test234 ~]# mysqlshow -uroot -p mysql
Enter password: 
Database: mysql
+------------------------------------------------------+
|                        Tables                        |
+------------------------------------------------------+
| columns_priv                                         |
| component                                            |
| db                                                   |
| default_roles                                        |
| engine_cost                                          |
| func                                                 |
| general_log                                          |
| global_grants                                        |
| gtid_executed                                        |
| help_category                                        |
| help_keyword                                         |
| help_relation                                        |
| help_topic                                           |
| innodb_index_stats                                   |
| innodb_table_stats                                   |
| password_history                                     |
| plugin                                               |
| procs_priv                                           |
| proxies_priv                                         |
| replication_asynchronous_connection_failover         |
| replication_asynchronous_connection_failover_managed |
| replication_group_configuration_version              |
| replication_group_member_actions                     |
| role_edges                                           |
| 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                                                 |
+------------------------------------------------------+
[root@test234 ~]# mysqlshow -uroot -p django -v
Enter password:
Database: django
+----------------------------+----------+
| Tables | Columns |
+----------------------------+----------+
| auth_group | 2 |
| auth_group_permissions | 3 |
| auth_permission | 4 |
| auth_user | 11 |
| auth_user_groups | 3 |
| auth_user_user_permissions | 3 |
| django_admin_log | 8 |
| django_content_type | 3 |
| django_migrations | 4 |
| django_session | 3 |
+----------------------------+----------+
10 rows in set.

[root@test234 ~]# mysqlshow -uroot -p django -vv
Enter password:
Database: django
+----------------------------+----------+------------+
| Tables | Columns | Total Rows |
+----------------------------+----------+------------+
| auth_group | 2 | 0 |
| auth_group_permissions | 3 | 0 |
| auth_permission | 4 | 24 |
| auth_user | 11 | 0 |
| auth_user_groups | 3 | 0 |
| auth_user_user_permissions | 3 | 0 |
| django_admin_log | 8 | 0 |
| django_content_type | 3 | 6 |
| django_migrations | 4 | 18 |
| django_session | 3 | 0 |
+----------------------------+----------+------------+
10 rows in set.
View Code
posted @ 2022-06-23 10:36  咿呀哒喏  阅读(323)  评论(0编辑  收藏  举报