MySQL初始化以及客户端工具的使用
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.什么是关系型数据库
关系型数据库通常是把所有的数据都组织成二维关系。之所以称为关系型数据库是因为他把数据组织在一个有字段和记录组成的二维关系表当中。并且在这个关系表之外提供了很多辅助性的工具以完成关系表中的关系的维持及数据访问等功能。
我们知道如果将数据存储为字符形式的时候有文本对象和二进制大对象。二进制大对象不会直接存储在数据库中,而是放在服务器的某一个路径上,而在数据库存储的知识该数据的指针。比如,存取一张高清壁纸,它不会将这个图片的内容直接写入数据库,而是将这个图片的绝对路径存放在数据库中的某一个字段内。这种关系我们称之为面向对象的关系型数据库。(RDBMS)。而现在很多关系型数据库还支持直接将xml格式的接口进行交互。
二.关系型数据库的分支
在90年代初,关系型数据库由Sybase,Informix,Oracle三家公司三足鼎立。这三家公司对公司的规划不同,Sybase和Informix的规划都是很有前瞻性的,而Oracle的目标很有精确,就是把它们的产品做好,最后Oracle不断地进行完善,很显然,走到最靠前的当然是Oracle。其中Sybase曾经是和Microsoft公司合作,当时处于某种原因Sybase退出和Microsoft公司的合作,最后Microsoft公司自己研发了SQL Server数据库,Informix公司则被IBM公司收购,现在Informix只是IBM的一个子项目公司,典型的数据库代表就是DB2。
早期MySQL是ab公司的,最后以10美元卖给了sun公司,不幸的是sun公司被Oracle公司收购了,而Oracle惯用的伎俩就是将竞争对手买下来再打入冷宫。所以在资本主义面前谈理想都是道德主义。sun公司被收购之后,MySQL也就归Oracle公司啦。Oracle和人们预想的一样,虽然在收购的时候承诺了5年之内不下手,但事实上在这期间MySQL以及被蹂躏了无数遍啦。所以像之前谷歌,Facebook等公司也从MySQL软件转向其他软件啦。而且在RHEL7版本的默认数据库已经将MySQL换成了MariaDB。
MySQL的原作者在sum公司被收购之后久另立门户了,在早起的MySQL的基础上提出了另外的一个分支叫MariaDB。事实上MariaDB在能够兼容mysql的基础上还整合了开源社区中的很强大的技术力量。我们知道mysql早起整合进来的存储引擎有一个是innodb,而innodb是属于innobase公司的,innobase公司早在2008年被Oracle收购啦。有幸的是在开源界总是不乏奇人的,比如说著名的percona公司,它是致力于mysql的优化方面已经取得了不菲成绩的一个组织,这个组织在早起的改进开源的innodb基础之上研发了增强版的innodb,命名为xtradb。如你所料,MariaDB的存储引擎就是用的xtradb。我们可以理解为MariaDB是MySQL进化之后的一个产品。google和Facebook等著名的世界互联网公司都很看好MariaDB并已经开始使用该软件啦。
其实google和Facebook还有其他的几家公司在早起的MySQL的技术理念的不同他们也开发了另一个互联网产品叫做webscaledb,专门为web而生的一个数据库系统。它柔和了MySQL,MariaDB,percona和innobase四家公司的技术的产品。
在开源的数据库产品中还有一个重要的产品叫做PostgreSQL(简称pgsql),事实上,早起名字叫做egresql,只是egresql在商业运作上跟Oracle竞争时完全败下阵来。以至于它销声匿迹的比Informix还要早。而事实上就关系型数据库来讲,pgsql在技术上要优秀的多。不过市场决定一切,因此MySQL可能是大家接触比较多的关系型数据库。
指定一提的另外一个关系型数据库叫做sqlite,它和mysql不一样,我们知道mysql是基于c/s架构,客户端和服务端是通过mysql协议进行通信的。而sqlite是一个简单,工作在本地,非服务化的一个API的关系型数据库接口(它的客户端和服务端是一体的)。注意,sqlite仅是一个引擎,sqlite主要用在嵌入式平台上又不得不用关系型数据库接口的这样的应用场景。再次强调一下,sqlite是一个非C./S架构,它纯粹是一个引擎API机制,背后的数据任然存储为文件系统上的简单文件,不做过多解析,但完全可以支持我们的程序员使用select,insert等机制对数据完成持久化。
三.MySQL的初始化
我们知道MySQL的安装方式有很多种,比如rpm,yum,源码安装,二进制方式安装MySQL等等。但是无论哪种方式安装的MySQL我们都需要做一个操作就是MySQL的初始化。而正确的初始化姿势我们分为两个操作。第一,提供配置文件;第二,删除匿名用户等等。
1.提供配置文件
相比之前接触过MySQL的童鞋都知道,MySQL默认的配置文件都是以“*.cnf”结尾的文件,它是集中式的配置文件,多个应用程序共用的配置文件。当然,也可以不这样玩,后期我会分享案例给大家。我们通过一条命令就可以查看MySQL的一些默认信息。即“[root@yinzhengjie ~]# mysql --help --verbose ”没错,通过这个命令我们就可以或得很多输出:
A>.显示mysqld程序启动时可用的选项,通常都是长选项;
B>.显示mysqld的配置文件中可用的服务变量;
C>.显示使用配置文件的方式,即:第一,它依次查找每个需要查找的文件,结果是所有文件并集;第二,如果某参数在多个文件中出现多次,后读取的最终生效。
2.重置用户信息
大家知道在一个新安装的服务器上有很多默认的用户,比如root以及一些匿名用户,他们都是没有密码的,这样是很不安全的,因此我们需要删除不必要的用户,以及给我们需要使用的用户设置密码以及授权操作。 我们知道MySQL用户名账号由两部分组成,即用户名和主机名(username@host),其中“host”还可以使用通配符。如 “%”表示任意长度的任意字符,“_”表示匹配任意单个字符。
A.删除匿名用户
mysql> select user,host,password from user;
+-------------+-------------+-------------------------------------------+
| user | host | password |
+-------------+-------------+-------------------------------------------+
| root | localhost | |
| root | yinzhengjie | |
| root | 127.0.0.1 | |
| | localhost | |
| | yinzhengjie | |
| yinzhengjie | .%.%.% | *C260A4F79FA905AF65142FFE0B9A14FE0E1519CC |
+-------------+-------------+-------------------------------------------+
rows in set (0.00 sec) mysql>
mysql>
mysql>
mysql>
mysql> drop user ""@localhost;
Query OK, rows affected (0.01 sec) mysql> drop user ""@yinzhengjie;
Query OK, rows affected (0.00 sec) mysql> select user,host,password from user;
+-------------+-------------+-------------------------------------------+
| user | host | password |
+-------------+-------------+-------------------------------------------+
| root | localhost | |
| root | yinzhengjie | |
| root | 127.0.0.1 | |
| yinzhengjie | .%.%.% | *C260A4F79FA905AF65142FFE0B9A14FE0E1519CC |
+-------------+-------------+-------------------------------------------+
rows in set (0.00 sec) mysql>
B.给所有的root用户设置密码
第一种方式:
mysql > set password for username@host = password( 'your_password');
第二种方法
mysql > update user set password = password('your_password') where user = 'root';
mysql > flush peivileges;
第三种方式:
[root@yinzhengjie ~]#mysqladmin -u UserName -h Host password 'new_password' -p
[root@yinzhengjie ~]#mysqladmin -u UserName -h Host -p flush-privileges
四.连入MySQL服务器
1.MySQL协议
MySQL的客户端有很多种,不论是那种MySQL客户端连接mysqld服务器,都是需要使用mysql protocol协议。
2.MySQL接收连接请求
本地通信:
客户端与服务器端位于同一主机,而且还要基于127.0.0.1(localhost)地址或lo接口进行通信。Linux或是Unix操作系统则是通过Unix Sock,/tmp/mysql.scok,/var/lib/mysql/mysql.sock这些本地文件进行进程间的通信。Widows则是通过memory(共享内存) pipe(命名管道)的方式进行通信的。
远程通信:
客户端与服务器位于不同的主机,或在统一主机便使用非回环地址通信。而远程通信时,通常是基于套接字通信,即TCP Socket。
3.MySQL客户端工具
事实上MySQL的客户端工具有很多种,可不止mysql这一种哟(只不过mysql这个客户端时最著名的一个)。其他著名的客户端工具还有:mysqladmin,mysqldump,mysqlcheck等等。
客户端([client])通信的选项:
指定用户 : -u,--user=
指定主机名 : -h, --host=
指定密码 : -p, --password=
指定协议 : --protocol={tcp|socket|memory|pipe}
指定端口 : --port= #MySQL默认是3306端口
指定套接字 : --socket= # 例如:/tmp/mysql.sock
非客户端类的管理工具:myisamchk(监测工具)和myisampack(打包工具)。
4.mysql命令行选项
压缩传输 : -compress
字符集 : --default-character-set
显示版本号 : -V:
显示详细信息 : -v:
指定ca证书 : --ssl-ca
ca证书的文件夹: --ssl-capath (一般有多个CA证书,就可以指定一个目录)
客户端证书 : --ssl-cert
加密方式 : --ssl-cipher
使用的私钥 : --ssl-key
验证服务器端证书: --ssl-verify-server-cert
指定要使用的数据库:--database= -D
输出结果为html格式的文档::-H --html
输出结果为xml格式的文档: -X --xml:
发送命令时拒绝使用无where字句的uodate或delete命令: --safe-updates
5.mysql命令提示符
mysql> ---->等待输入命令
'> ---->前面提供的‘未提供结束’,接下来那两行一样的道理。
”>
`>
—> ---->续航提示符
/*> ---->注释信息(结束就用户"*/",比如:/*yinzhengjie*>)
6.mysql的命令行编辑快捷键
ctrl+w:删除光标所在处之前的一个单词
ctrl+u:删除光标之前至行首的所有内容,并将其保存在缓存(buffer)当中。
ctrl+y:粘贴之前ctrl+w或ctrl+u删除的内容
ctrl+a:移动光标至行首
ctrl+e:移动光标至行尾
五.mysqladmin工具用法详解
mysqladmin可以让用户不进入mysql的交互界面,直接在命令行就可以运行SQL语句啦。命令格式:“mysqladmin [options] command [arg] [command[arg]] .....”,接下来,让我们一起研究一下mysqladmin的用法。这个命令其实很有用,尤其是你在写shell脚本的时候,操作数据的时候它的用法就可以大展身手了。
1.创建空数据库
[root@yinzhengjie ~]# mysqladmin create yinzhengjiedb #创建一个叫yinzhengjiedb的数据库。
[root@yinzhengjie ~]# mysql -e 'show databases;' #我们可以用mysql的-e选项来进行验证是否创建成功、
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| yinzhengjie |
| yinzhengjiedb |
+--------------------+
[root@yinzhengjie ~]#
2.删除数据库
[root@yinzhengjie ~]# mysql -e 'show databases;'
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| yinzhengjie |
| yinzhengjiedb |
+--------------------+
[root@yinzhengjie ~]# mysqladmin drop yinzhengjiedb
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 'yinzhengjiedb' database [y/N] y #此处我们需要交互式输入一个y。
Database "yinzhengjiedb" dropped
[root@yinzhengjie ~]# mysql -e 'show databases;'
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| yinzhengjie |
+--------------------+
[root@yinzhengjie ~]#
3.输出MySQL简要状态信息
[root@yinzhengjie ~]# mysqladmin status #输出简要状态信息
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mysqladmin status --sleep --count 5 #表示每个1秒刷新一次,总共打印5次
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mysqladmin status --sleep #表示每秒刷新一次,可以安装Ctrl+C 结束
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
Uptime: Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.0
^C[root@yinzhengjie ~]#
4.debug 调试信息用法展示
[root@yinzhengjie ~]# more /var/log/mysqld.log
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mysqladmin debug
[root@yinzhengjie ~]# more /var/log/mysqld.log Memory status:
Non-mmapped space allocated from system:
Number of free chunks:
Number of fastbin blocks:
Number of mmapped regions:
Space in mmapped regions:
Maximum total allocated space:
Space available in freed fastbin blocks:
Total allocated space:
Total free space:
Top-most, releasable space:
Estimated memory (with thread stack): Events status:
LLA = Last Locked At LUA = Last Unlocked At
WOC = Waiting On Condition DL = Data Locked Event scheduler status:
State : INITIALIZED
Thread id :
LLA : n/a:
LUA : n/a:
WOC : NO
Workers :
Executed :
Data locked: NO Event queue status:
Element count :
Data locked : NO
Attempting lock : NO
LLA : drop_schema_events:
LUA : drop_schema_events:
WOC : NO
Next activation : never Status information: Current dir: /var/lib/mysql/
Running threads: Stack size:
Current locks:
lock: 0x7f7740089338: lock: 0x7f7740086ee8: lock: 0x7f77400847b8: lock: 0x7f77400823f8: lock: 0x7f7740080488: lock: 0x7f774007f398: lock: 0x7f7740072028: lock: 0x7f774006ba58: lock: 0x7f7740069368: lock: 0x7f7740065678: lock: 0x7f7740061a98: lock: 0x7f774005ede8: lock: 0x7f774005b838: lock: 0x7f77400595c8: lock: 0x7f774004ed08: lock: 0x7f774004a758: lock: 0x7f7740044c38: lock: 0x7f77400400b8: lock: 0x7f77400377c8: lock: 0x7f7740031ed8: lock: 0x7f7740029c08: lock: 0x7f7740027cf8: lock: 0x7f7740024308: lock: 0x7f774001e728: lock: 0x7f77400158e8: lock: 0x7f774000ceb8: lock: 0x291f5f8: lock: 0x29148c8: lock: 0x2909d28: lock: 0x2900de8: lock: 0x28f65f8: lock: 0x28e6f58: lock: 0x28e1098: lock: 0x28d93f8: Key caches:
default
Buffer_size:
Block_size:
Division_limit:
Age_limit:
blocks used:
not flushed:
w_requests:
writes:
r_requests:
reads: handler status:
read_key:
read_next:
read_rnd
read_first:
write:
delete
update: Table status:
Opened tables:
Open tables:
Open files:
Open streams: Alarm status:
Active alarms:
Max used alarms:
Next alarm time: Begin safemalloc memory dump: End safemalloc memory dump.
[root@yinzhengjie ~]#
debug 打开调试日志并记录与error log中
5.extended-status用法展示
[root@yinzhengjie ~]# mysqladmin extended-status
+-----------------------------------+----------+
| Variable_name | Value |
+-----------------------------------+----------+
| Aborted_clients | |
| Aborted_connects | |
| Binlog_cache_disk_use | |
| Binlog_cache_use | |
| Bytes_received | |
| Bytes_sent | |
| Com_admin_commands | |
| Com_assign_to_keycache | |
| Com_alter_db | |
| Com_alter_db_upgrade | |
| Com_alter_event | |
| Com_alter_function | |
| Com_alter_procedure | |
| Com_alter_server | |
| Com_alter_table | |
| Com_alter_tablespace | |
| Com_analyze | |
| Com_backup_table | |
| Com_begin | |
| Com_binlog | |
| Com_call_procedure | |
| Com_change_db | |
| Com_change_master | |
| Com_check | |
| Com_checksum | |
| Com_commit | |
| Com_create_db | |
| Com_create_event | |
| Com_create_function | |
| Com_create_index | |
| Com_create_procedure | |
| Com_create_server | |
| Com_create_table | |
| Com_create_trigger | |
| Com_create_udf | |
| Com_create_user | |
| Com_create_view | |
| Com_dealloc_sql | |
| Com_delete | |
| Com_delete_multi | |
| Com_do | |
| Com_drop_db | |
| Com_drop_event | |
| Com_drop_function | |
| Com_drop_index | |
| Com_drop_procedure | |
| Com_drop_server | |
| Com_drop_table | |
| Com_drop_trigger | |
| Com_drop_user | |
| Com_drop_view | |
| Com_empty_query | |
| Com_execute_sql | |
| Com_flush | |
| Com_grant | |
| Com_ha_close | |
| Com_ha_open | |
| Com_ha_read | |
| Com_help | |
| Com_insert | |
| Com_insert_select | |
| Com_install_plugin | |
| Com_kill | |
| Com_load | |
| Com_load_master_data | |
| Com_load_master_table | |
| Com_lock_tables | |
| Com_optimize | |
| Com_preload_keys | |
| Com_prepare_sql | |
| Com_purge | |
| Com_purge_before_date | |
| Com_release_savepoint | |
| Com_rename_table | |
| Com_rename_user | |
| Com_repair | |
| Com_replace | |
| Com_replace_select | |
| Com_reset | |
| Com_restore_table | |
| Com_revoke | |
| Com_revoke_all | |
| Com_rollback | |
| Com_rollback_to_savepoint | |
| Com_savepoint | |
| Com_select | |
| Com_set_option | |
| Com_show_authors | |
| Com_show_binlog_events | |
| Com_show_binlogs | |
| Com_show_charsets | |
| Com_show_collations | |
| Com_show_column_types | |
| Com_show_contributors | |
| Com_show_create_db | |
| Com_show_create_event | |
| Com_show_create_func | |
| Com_show_create_proc | |
| Com_show_create_table | |
| Com_show_create_trigger | |
| Com_show_databases | |
| Com_show_engine_logs | |
| Com_show_engine_mutex | |
| Com_show_engine_status | |
| Com_show_events | |
| Com_show_errors | |
| Com_show_fields | |
| Com_show_function_status | |
| Com_show_grants | |
| Com_show_keys | |
| Com_show_master_status | |
| Com_show_new_master | |
| Com_show_open_tables | |
| Com_show_plugins | |
| Com_show_privileges | |
| Com_show_procedure_status | |
| Com_show_processlist | |
| Com_show_profile | |
| Com_show_profiles | |
| Com_show_slave_hosts | |
| Com_show_slave_status | |
| Com_show_status | |
| Com_show_storage_engines | |
| Com_show_table_status | |
| Com_show_tables | |
| Com_show_triggers | |
| Com_show_variables | |
| Com_show_warnings | |
| Com_slave_start | |
| Com_slave_stop | |
| Com_stmt_close | |
| Com_stmt_execute | |
| Com_stmt_fetch | |
| Com_stmt_prepare | |
| Com_stmt_reprepare | |
| Com_stmt_reset | |
| Com_stmt_send_long_data | |
| Com_truncate | |
| Com_uninstall_plugin | |
| Com_unlock_tables | |
| Com_update | |
| Com_update_multi | |
| Com_xa_commit | |
| Com_xa_end | |
| Com_xa_prepare | |
| Com_xa_recover | |
| Com_xa_rollback | |
| Com_xa_start | |
| Compression | OFF |
| Connections | |
| Created_tmp_disk_tables | |
| Created_tmp_files | |
| Created_tmp_tables | |
| Delayed_errors | |
| Delayed_insert_threads | |
| Delayed_writes | |
| Flush_commands | |
| Handler_commit | |
| Handler_delete | |
| Handler_discover | |
| Handler_prepare | |
| Handler_read_first | |
| Handler_read_key | |
| Handler_read_next | |
| Handler_read_prev | |
| Handler_read_rnd | |
| Handler_read_rnd_next | |
| Handler_rollback | |
| Handler_savepoint | |
| Handler_savepoint_rollback | |
| Handler_update | |
| Handler_write | |
| Innodb_buffer_pool_pages_data | |
| Innodb_buffer_pool_pages_dirty | |
| Innodb_buffer_pool_pages_flushed | |
| Innodb_buffer_pool_pages_free | |
| Innodb_buffer_pool_pages_misc | |
| Innodb_buffer_pool_pages_total | |
| Innodb_buffer_pool_read_ahead_rnd | |
| Innodb_buffer_pool_read_ahead_seq | |
| Innodb_buffer_pool_read_requests | |
| Innodb_buffer_pool_reads | |
| Innodb_buffer_pool_wait_free | |
| Innodb_buffer_pool_write_requests | |
| Innodb_data_fsyncs | |
| Innodb_data_pending_fsyncs | |
| Innodb_data_pending_reads | |
| Innodb_data_pending_writes | |
| Innodb_data_read | |
| Innodb_data_reads | |
| Innodb_data_writes | |
| Innodb_data_written | |
| Innodb_dblwr_pages_written | |
| Innodb_dblwr_writes | |
| Innodb_log_waits | |
| Innodb_log_write_requests | |
| Innodb_log_writes | |
| Innodb_os_log_fsyncs | |
| Innodb_os_log_pending_fsyncs | |
| Innodb_os_log_pending_writes | |
| Innodb_os_log_written | |
| Innodb_page_size | |
| Innodb_pages_created | |
| Innodb_pages_read | |
| Innodb_pages_written | |
| Innodb_row_lock_current_waits | |
| Innodb_row_lock_time | |
| Innodb_row_lock_time_avg | |
| Innodb_row_lock_time_max | |
| Innodb_row_lock_waits | |
| Innodb_rows_deleted | |
| Innodb_rows_inserted | |
| Innodb_rows_read | |
| Innodb_rows_updated | |
| Key_blocks_not_flushed | |
| Key_blocks_unused | |
| Key_blocks_used | |
| Key_read_requests | |
| Key_reads | |
| Key_write_requests | |
| Key_writes | |
| Last_query_cost | 0.000000 |
| Max_used_connections | |
| Not_flushed_delayed_rows | |
| Open_files | |
| Open_streams | |
| Open_table_definitions | |
| Open_tables | |
| Opened_files | |
| Opened_table_definitions | |
| Opened_tables | |
| Prepared_stmt_count | |
| Qcache_free_blocks | |
| Qcache_free_memory | |
| Qcache_hits | |
| Qcache_inserts | |
| Qcache_lowmem_prunes | |
| Qcache_not_cached | |
| Qcache_queries_in_cache | |
| Qcache_total_blocks | |
| Queries | |
| Questions | |
| Rpl_status | NULL |
| Select_full_join | |
| Select_full_range_join | |
| Select_range | |
| Select_range_check | |
| Select_scan | |
| Slave_open_temp_tables | |
| Slave_retried_transactions | |
| Slave_running | OFF |
| Slow_launch_threads | |
| Slow_queries | |
| Sort_merge_passes | |
| Sort_range | |
| Sort_rows | |
| Sort_scan | |
| Ssl_accept_renegotiates | |
| Ssl_accepts | |
| Ssl_callback_cache_hits | |
| Ssl_cipher | |
| Ssl_cipher_list | |
| Ssl_client_connects | |
| Ssl_connect_renegotiates | |
| Ssl_ctx_verify_depth | |
| Ssl_ctx_verify_mode | |
| Ssl_default_timeout | |
| Ssl_finished_accepts | |
| Ssl_finished_connects | |
| Ssl_session_cache_hits | |
| Ssl_session_cache_misses | |
| Ssl_session_cache_mode | NONE |
| Ssl_session_cache_overflows | |
| Ssl_session_cache_size | |
| Ssl_session_cache_timeouts | |
| Ssl_sessions_reused | |
| Ssl_used_session_cache_entries | |
| Ssl_verify_depth | |
| Ssl_verify_mode | |
| Ssl_version | |
| Table_locks_immediate | |
| Table_locks_waited | |
| Tc_log_max_pages_used | |
| Tc_log_page_size | |
| Tc_log_page_waits | |
| Threads_cached | |
| Threads_connected | |
| Threads_created | |
| Threads_running | |
| Uptime | |
| Uptime_since_flush_status | |
+-----------------------------------+----------+
[root@yinzhengjie ~]#
输出mysq的各状态变量及数值,相当于执行“mysql> show global status”
6.flush-hosts
[root@yinzhengjie ~]# mysqladmin flush-hosts #清空主机相关的缓存:DNS解析缓存,此前因为连接错误次数过多而被拒绝访问mysqld的主机列表
[root@yinzhengjie ~]#
7. flush-logs
[root@yinzhengjie ~]# mysqladmin flush-logs #日志滚动,主要是二进制日志和中继日志
[root@yinzhengjie ~]#
8.refresh
[root@yinzhengjie ~]# mysqladmin refresh #相当于同时使用flush-logs和flush-hosts
[root@yinzhengjie ~]#
9.flush-privileges
[root@yinzhengjie ~]# mysqladmin flush-privileges #通知服务器重读授权表
[root@yinzhengjie ~]#
10.reload
[root@yinzhengjie ~]# mysqladmin reload #重载授权表,相当于flush-privileges
[root@yinzhengjie ~]#
11.flush-status
[root@yinzhengjie ~]# mysqladmin flush-status #重置状态变量的值
[root@yinzhengjie ~]#
12.flush-tables
[root@yinzhengjie ~]# mysqladmin flush-tables #关闭当前打开的表文件句柄
[root@yinzhengjie ~]#
13.flush-threads
[root@yinzhengjie ~]# mysqladmin flush-threads #清空线程缓存
[root@yinzhengjie ~]#
14.kill
[root@yinzhengjie ~]# mysqladmin kill #需要输入线程ID哟
mysqladmin: Too few arguments to 'kill'
[root@yinzhengjie ~]#
15.processlist
[root@yinzhengjie ~]# mysqladmin processlist #线程列表
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| | root | localhost | | Query | | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
[root@yinzhengjie ~]#
16.password
[root@yinzhengjie ~]# mysqladmin -u root -h localhost password 'yinzhengjie' -p
Enter password: -------->注意,由于我的数据库一开始是没有设置密码的,因此我这里是第一次给我的数据库设置密码,这里要求我们输入以前的密码我们直接回车即可。
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mysqladmin -u root -h localhost -pyinzhengjie flush-privileges #需要刷新一下授权。
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mysql -pyinzhengjie #验证是否可用正常登陆。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.1. Source distribution Copyright (c) , , 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>
17.ping
[root@yinzhengjie ~]# mysqladmin -pyinzhengjie ping #判断MySQL是否在线。
mysqld is alive
[root@yinzhengjie ~]#
18.shutdown
[root@yinzhengjie ~]# mysqladmin -pyinzhengjie shutdown #关闭mysqld进程
[root@yinzhengjie ~]# lsof -i:
[root@yinzhengjie ~]#
19.start-slave
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mysqladmin -pyinzhengjie start-slave #启动从服务器进程
20.stop-slave
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mysqladmin -pyinzhengjie stop-slave #关闭从服务器进程
21.variables
[root@yinzhengjie ~]# mysqladmin -pyinzhengjie variables
+-----------------------------------------+-------------------------------------------------------------------------------------------+
| Variable_name | Value |
+-----------------------------------------+-------------------------------------------------------------------------------------------+
| auto_increment_increment | |
| auto_increment_offset | |
| autocommit | ON |
| automatic_sp_privileges | ON |
| back_log | |
| basedir | /usr/ |
| big_tables | OFF |
| binlog_cache_size | |
| binlog_direct_non_transactional_updates | OFF |
| binlog_format | STATEMENT |
| bulk_insert_buffer_size | |
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
| completion_type | |
| concurrent_insert | |
| connect_timeout | |
| datadir | /var/lib/mysql/ |
| date_format | %Y-%m-%d |
| datetime_format | %Y-%m-%d %H:%i:%s |
| default_week_format | |
| delay_key_write | ON |
| delayed_insert_limit | |
| delayed_insert_timeout | |
| delayed_queue_size | |
| div_precision_increment | |
| engine_condition_pushdown | ON |
| error_count | |
| event_scheduler | OFF |
| expire_logs_days | |
| flush | OFF |
| flush_time | |
| foreign_key_checks | ON |
| ft_boolean_syntax | + -><()~*:""&| |
| ft_max_word_len | |
| ft_min_word_len | |
| ft_query_expansion_limit | |
| ft_stopword_file | (built-in) |
| general_log | OFF |
| general_log_file | /var/run/mysqld/mysqld.log |
| group_concat_max_len | |
| have_community_features | YES |
| have_compress | YES |
| have_crypt | YES |
| have_csv | YES |
| have_dynamic_loading | YES |
| have_geometry | YES |
| have_innodb | YES |
| have_ndbcluster | NO |
| have_openssl | DISABLED |
| have_partitioning | YES |
| have_query_cache | YES |
| have_rtree_keys | YES |
| have_ssl | DISABLED |
| have_symlink | DISABLED |
| hostname | yinzhengjie |
| identity | |
| ignore_builtin_innodb | OFF |
| init_connect | |
| init_file | |
| init_slave | |
| innodb_adaptive_hash_index | ON |
| innodb_additional_mem_pool_size | |
| innodb_autoextend_increment | |
| innodb_autoinc_lock_mode | |
| innodb_buffer_pool_size | |
| innodb_checksums | ON |
| innodb_commit_concurrency | |
| innodb_concurrency_tickets | |
| innodb_data_file_path | ibdata1:10M:autoextend |
| innodb_data_home_dir | |
| innodb_doublewrite | ON |
| innodb_fast_shutdown | |
| innodb_file_io_threads | |
| innodb_file_per_table | OFF |
| innodb_flush_log_at_trx_commit | |
| innodb_flush_method | |
| innodb_force_recovery | |
| innodb_lock_wait_timeout | |
| innodb_locks_unsafe_for_binlog | OFF |
| innodb_log_buffer_size | |
| innodb_log_file_size | |
| innodb_log_files_in_group | |
| innodb_log_group_home_dir | ./ |
| innodb_max_dirty_pages_pct | |
| innodb_max_purge_lag | |
| innodb_mirrored_log_groups | |
| innodb_open_files | |
| innodb_rollback_on_timeout | OFF |
| innodb_stats_method | nulls_equal |
| innodb_stats_on_metadata | ON |
| innodb_support_xa | ON |
| innodb_sync_spin_loops | |
| innodb_table_locks | ON |
| innodb_thread_concurrency | |
| innodb_thread_sleep_delay | |
| innodb_use_legacy_cardinality_algorithm | ON |
| insert_id | |
| interactive_timeout | |
| join_buffer_size | |
| keep_files_on_create | OFF |
| key_buffer_size | |
| key_cache_age_threshold | |
| key_cache_block_size | |
| key_cache_division_limit | |
| language | /usr/share/mysql/english/ |
| large_files_support | ON |
| large_page_size | |
| large_pages | OFF |
| last_insert_id | |
| lc_time_names | en_US |
| license | GPL |
| local_infile | ON |
| locked_in_memory | OFF |
| log | OFF |
| log_bin | OFF |
| log_bin_trust_function_creators | OFF |
| log_bin_trust_routine_creators | OFF |
| log_error | /var/log/mysqld.log |
| log_output | FILE |
| log_queries_not_using_indexes | OFF |
| log_slave_updates | OFF |
| log_slow_queries | OFF |
| log_warnings | |
| long_query_time | 10.000000 |
| low_priority_updates | OFF |
| lower_case_file_system | OFF |
| lower_case_table_names | |
| max_allowed_packet | |
| max_binlog_cache_size | |
| max_binlog_size | |
| max_connect_errors | |
| max_connections | |
| max_delayed_threads | |
| max_error_count | |
| max_heap_table_size | |
| max_insert_delayed_threads | |
| max_join_size | |
| max_length_for_sort_data | |
| max_long_data_size | |
| max_prepared_stmt_count | |
| max_relay_log_size | |
| max_seeks_for_key | |
| max_sort_length | |
| max_sp_recursion_depth | |
| max_tmp_tables | |
| max_user_connections | |
| max_write_lock_count | |
| min_examined_row_limit | |
| multi_range_count | |
| myisam_data_pointer_size | |
| myisam_max_sort_file_size | |
| myisam_mmap_size | |
| myisam_recover_options | OFF |
| myisam_repair_threads | |
| myisam_sort_buffer_size | |
| myisam_stats_method | nulls_unequal |
| myisam_use_mmap | OFF |
| net_buffer_length | |
| net_read_timeout | |
| net_retry_count | |
| net_write_timeout | |
| new | OFF |
| old | OFF |
| old_alter_table | OFF |
| old_passwords | OFF |
| open_files_limit | |
| optimizer_prune_level | |
| optimizer_search_depth | |
| optimizer_switch | index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on |
| pid_file | /var/run/mysqld/mysqld.pid |
| plugin_dir | /usr/lib64/mysql/plugin |
| port | |
| preload_buffer_size | |
| profiling | OFF |
| profiling_history_size | |
| protocol_version | |
| pseudo_thread_id | |
| query_alloc_block_size | |
| query_cache_limit | |
| query_cache_min_res_unit | |
| query_cache_size | |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | |
| rand_seed1 | |
| rand_seed2 | |
| range_alloc_block_size | |
| read_buffer_size | |
| read_only | OFF |
| read_rnd_buffer_size | |
| relay_log | |
| relay_log_index | |
| relay_log_info_file | relay-log.info |
| relay_log_purge | ON |
| relay_log_space_limit | |
| report_host | |
| report_password | |
| report_port | |
| report_user | |
| rpl_recovery_rank | |
| secure_auth | OFF |
| secure_file_priv | |
| server_id | |
| skip_external_locking | ON |
| skip_name_resolve | OFF |
| skip_networking | OFF |
| skip_show_database | OFF |
| slave_compressed_protocol | OFF |
| slave_exec_mode | STRICT |
| slave_load_tmpdir | /tmp |
| slave_max_allowed_packet | |
| slave_net_timeout | |
| slave_skip_errors | OFF |
| slave_transaction_retries | |
| slow_launch_time | |
| slow_query_log | OFF |
| slow_query_log_file | /var/run/mysqld/mysqld-slow.log |
| socket | /var/lib/mysql/mysql.sock |
| sort_buffer_size | |
| sql_auto_is_null | ON |
| sql_big_selects | ON |
| sql_big_tables | OFF |
| sql_buffer_result | OFF |
| sql_log_bin | ON |
| sql_log_off | OFF |
| sql_log_update | ON |
| sql_low_priority_updates | OFF |
| sql_max_join_size | |
| sql_mode | |
| sql_notes | ON |
| sql_quote_show_create | ON |
| sql_safe_updates | OFF |
| sql_select_limit | |
| sql_slave_skip_counter | |
| sql_warnings | OFF |
| ssl_ca | |
| ssl_capath | |
| ssl_cert | |
| ssl_cipher | |
| ssl_key | |
| storage_engine | MyISAM |
| sync_binlog | |
| sync_frm | ON |
| system_time_zone | PST |
| table_definition_cache | |
| table_lock_wait_timeout | |
| table_open_cache | |
| table_type | MyISAM |
| thread_cache_size | |
| thread_handling | one-thread-per-connection |
| thread_stack | |
| time_format | %H:%i:%s |
| time_zone | SYSTEM |
| timed_mutexes | OFF |
| timestamp | |
| tmp_table_size | |
| tmpdir | /tmp |
| transaction_alloc_block_size | |
| transaction_prealloc_size | |
| tx_isolation | REPEATABLE-READ |
| unique_checks | ON |
| updatable_views_with_limit | YES |
| version | 5.1. |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | redhat-linux-gnu |
| wait_timeout | |
| warning_count | |
+-----------------------------------------+-------------------------------------------------------------------------------------------+
[root@yinzhengjie ~]#
variables:显示mysql的各服务器进程
六.GUI客户端工具
1>.Navicat for mysql
2>.SQLyog
3>.MySQL Front
4>.phpMyAdmin
5>.MySQL Query Browser
6>.MySQL Administrator
7>.MySQL Workbench