MySQL的衍生版:MariaDB、Percona-Server、AliSQL、TiDB;
MariaDB图形化管理工具:
phpMyAdmin,Navicat,Mysql-Front,ToadForMySQL,SQLyog;
1、MariaDB的特性:
1>插件式存储引擎;
存储管理器有多种实现版本,彼此间的功能和特性可能略有区别,用户可根据需要灵活选择;
存储引擎也称为”表类型”;
2>支持更多类型的存储引擎;
MyISAM:不支持事务,表级锁,数据库崩溃后不保证安全恢复;
Aria:由MyISAM发展而来,支持数据库崩溃后可安全恢复;
InnoDB:支持事务,行级锁,支持外键,支持热备;使用的是Percona-XtraDB,与mysql原生的InnoDB不同,只是名字相同而已;
… …
3>诸多扩展和新特性;
4>提供了较多的测试组件;
2、MariaDB的程序组成及对应管理命令;
1>MariaDB-server程序包提供的命令
mysqld;
mysqld_safe:服务端配置程序;
mysqld_multi:多实例;
2>MariaDB-client程序包
mysql:CLI交互式客户端程序;
mysqldump:备份工具;
mysqladmin:管理工具;
mysqlbinlog;
…
3、三类套接字地址;
IPv4 3306/TCP;端口通信方式;
IPv6 3306/TCP;端口通信方式;
Unix Sock(本机通信,套接字通信方式):套接字文件一般位于/var/lib/mysql/mysql.sock,或者/tmp/mysql.sock;
通过本机回环地址”127.0.0.1″进行通信;
备注,注意mysql.sock套接字文件的权限:
[root@localhost dbroot]# ll /var/lib/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Jun 5 11:34 /var/lib/mysql/mysql.sock
[root@localhost dbroot]#
4、MariaDB的配置文件;
1> ini风格,用一个文件为多个程序提供配置;
2> 服务端命令、客户端命令配置数据库后所产生的值都可以写入单独的文件放置在’/etc/my.cnf.d/’目录下,以’.cnf’结尾即可;
3>MariaDB的各类程序启动时要读取的配置文件不止一个,各个配置文件顺序读取,如果配置文件中有冲突,则最后读取的为最终生效;
查看MariaDB启动时读取配置文件的顺序,可使用如下命令:
~]# my_print_defaults
... ... Default options are read from the following files in the given order: /etc/my.cnf ~/.my.cnf ... ...
备注,”/etc/my.cnf”文件会读取”/etc/my.cnf.d/”目录下所有以’.cnf’结尾的文件;
5、MariaDB客户端命令
5.1 mysql命令
命令描述:mysql – the MariaDB command-line tool;
命令格式:mysql [options] db_name
常用选项:
-uUSERNAME: 指明用户名,默认为root;
-hHOST: 指定要连接的MariaDB服务器的IP地址,默认为localhost;
-p[PASSWORD]: 小写字母’p’,指定USERNAME的密码,默认为空;
-P PORT: 大写字母’P’,指定端口号;
-S /PATH/TO/mysql.sock :指定采用MariaDB的套接字’mysql.sock’进行连接通信;
-Ddb_name:连接到服务器端后,设定其处在指明的数据库为默认数据库;
-e ‘SQL COMMAND’: 连接至服务器并让其执行此命令后直接返回;
备注:
MariaDB的用户账号由2部分组成,’USERNAME’@’HOST’;
‘HOST’用于限制此用户可通过哪些远程主机连接数据库;
HOST的表示方式:
%:匹配任意长度的任意字符;
-:匹配任意单个字符;
举例:
当前主机IP为”192.168.206.88″,远程连接MariaDB服务器;
~]# mysql -uroot -h192.168.206.66 -S 192.168.206.66:/var/lib/mysql.sock -p
~]# mysql -uroot -h192.168.206.66 -S 192.168.206.66:/var/lib/mysql.sock -P 3306 -p
~]# mysql -uroot -h192.168.206.66 -h192.168.206.66 -p
~]# mysql -uroot -h192.168.206.66 -h192.168.206.66 -P 3306 -p
5.2 显示帮助信息,本地执行;
MariaDB [(none)]> help
General information about MariaDB can be found atMariaDB FoundationList of all MySQL commands: Note that all text commands must be first on line and end with ';' ? (\?) Synonym for `help'. clear (\c) Clear the current input statement. connect (\r) Reconnect to the server. Optional arguments are db and host. delimiter (\d) Set statement delimiter. edit (\e) Edit command with $EDITOR. ego (\G) Send command to mysql server, display result vertically. exit (\q) Exit mysql. Same as quit. go (\g) Send command to mysql server. help (\h) Display this help. nopager (\n) Disable pager, print to stdout. notee (\t) Don't write into outfile. pager (\P) Set PAGER [to_pager]. Print the query results via PAGER. print (\p) Print current command. prompt (\R) Change your mysql prompt. quit (\q) Quit mysql. rehash (\#) Rebuild completion hash. source (\.) Execute an SQL script file. Takes a file name as an argument. status (\s) Get status information from the server. system (\!) Execute a system shell command. tee (\T) Set outfile [to_outfile]. Append everything into given outfile. use (\u) Use another database. Takes database name as argument. charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets. warnings (\W) Show warnings after every statement. nowarning (\w) Don't show warnings after every statement. For server side help, type 'help contents'
上面命令做部分说明:
\u db_name:设定哪个库为默认数据库(要进行操作的数据库的库名);
\q:退出;
\g:语句结束标记;默认结束标记符为分号’;’,可以用’\g’代替分号;
\d:修改结束标记,默认结束标记符为分号’;’,如果要把分号结束标记修改为#号,则”\d #”;
\G:语句结束标记,以竖排方式显示结果;
\s:显示服务器的状态信息;
\c:作用类似与Linux系统中的”ctrl+c”;
\!:执行shll命令,后面空格,再跟文件系统里面存放的shell脚本文件完整路径;
\.:执行SQL脚本,后面空格,再跟文件系统里面存放的SQL脚本文件完整路径;
备注:shell脚本、SQL脚本所在的目录,此目录需要能让mysql用户(默认运行Mariadb的用户)有执行权限!!!
6、 MariaDB服务端命令(DDL,DML,DCL):
DDL:Data Defined Language,数据定义语言;操作指令有,CREATE,ALTER,DROP,…;
DML:Data Manipulation Language,数据操作语言;操作指令有,INSERT,DELETE,UPDATE,SELECT,…;
获取帮助:
MariaDB [(none)]> help contents
MariaDB [(none)]> help ‘命令类别’
You asked for help about help category: "Contents" For more information, type 'help <item>', where <item> is one of the following categories: Account Management ---------> 里面包含账户管理命令; Administration -----------> 里面包含服务器管理命令; Compound Statements Data Definition ----------> 里面包含的命令属于DDL类别; Data Manipulation ----------> 里面包含的命令属于DML类别; Data Types Functions Functions and Modifiers for Use with GROUP BY Geographic Features Help Metadata Language Structure ---------> 里面包含语言结构管理命令; Plugins ------------------> 里面包含插件管理命令; Procedures -----------------> 存储过程管理命令; Table Maintenance ----------> 表维护命令; Transactions ---------------> 事务管理命令; User-Defined Functions -----> 用户自定义函数命令; Utility