mysqladmin --version #验证 ##该命令将输出以下结果,该结果基于你的系统信息: mysqladmin Ver 8.42 Distrib 5.6.51, for Linux on x86_64 ###如果以上命令执行后未输出任何信息,说明你的mysql未安装成功
mysql #进入mysql ##执行简单命令(>提示符后面执行SQL命令) mysql> SHOW DATABASES; +----------+ | Database | +----------+ | mysql | | test | +----------+ 2 rows in set (0.13 sec)
创建密码
1 2
mysqladmin -u root password "000000" #创建root用户密码,密码为"000000" mysql -uroot -p000000 #进入数据库
注,:输入密码时密码不会显示,输入正确即可
管理MySQL
1 2 3 4 5 6 7 8 9 10
ps -ef | grep mysqld #检查mysql服务器是否启动 ##启动mysql服务器 cd /usr/bin ./mysqld_safe & ##关闭运行中的mysql服务器 cd /usr/bin ./mysqladmin -u root -p shutdown Enter password:******
SHOW DATABASES; #列出mysql中所有数据库 mysql> SHOW DATABASES; #实例 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec)
SHOW TABLES; #指定所有表,需要配合use命令指定数据库后使用
实例: MariaDB [(none)]> 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
SHOW COLUMNS FROM <数据表名> #查看数据表属性等信息 mysql> SHOW COLUMNS FROM db; +-----------------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+---------------+------+-----+---------+-------+ | Host | char(60) | NO | PRI | | | | Db | char(64) | NO | PRI | | | | User | char(16) | 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 | | | 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 | | | Create_tmp_table_priv | enum('N','Y') | NO | | N | | | Lock_tables_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 | | | Execute_priv | enum('N','Y') | NO | | N | | | Event_priv | enum('N','Y') | NO | | N | | | Trigger_priv | enum('N','Y') | NO | | N | | +-----------------------+---------------+------+-----+---------+-------+ 22 rows in set (0.00 sec)
SHOW INDEX FROM <数据表名>; #显示数据表的详细索引信息 mysql> SHOW INDEX FROM db; #实例 +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | db | 0 | PRIMARY | 1 | Host | A | NULL | NULL | NULL | | BTREE | | | | db | 0 | PRIMARY | 2 | Db | A | NULL | NULL | NULL | | BTREE | | | | db | 0 | PRIMARY | 3 | User | A | 2 | NULL | NULL | | BTREE | | | | db | 1 | User | 1 | User | A | 1 | NULL | NULL | | BTREE | | | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 4 rows in set (0.00 sec) mysql> SHOW TABLE STATUS FROM 'xxx'; # 显示数据库 xxx 中所有表的信息 mysql> SHOW TABLE STATUS from RUNOOB LIKE 'xxx%'; # 表名以xxx开头的表的信息 mysql> SHOW TABLE STATUS from RUNOOB LIKE 'xxx%'\G; # 加上 \G,查询结果按列打印
mysql -uroot -p000000 #登陆成功后,显示结果如下: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 14 Server version: 5.5.68-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.