一.MariaDB安装
1.安装命令
brew install mariadb
2.连接数据库创建用户mariadb并修改root密码
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
CREATE USER 'mariadb'@'%' IDENTIFIED BY 'mariadb';
3.给新用户mariadb授权
GRANT ALL ON *.* TO 'username’ @ '%';
GRANT ALL ON *.* TO 'mariadb’ @ '%';
4.修改root用户密码
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('password');
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('mariadb');
5.启动和停止数据库
mysqld
mysqladmin -u root -p shutdown
二.常用命令
1.查看版本信息
```mysqladmin --version```
2.客户端连接数据库
```mysql -u mariadb -p```
3.显示数据库当中的表
SHOW TABLES
4.显示数据表user结构信息
SHOW COLUMNS FROM USER
5.显示数据表索引信息
SHOW INDEX FROM USER
6.显示数据库中表状态信息
SHOW TABLE STATUS FROM MYSQL
7.创建数据库'NfDB'
CREATE DATABASE NfDB
8.删除数据库’NfDB‘
DROP DATABASE NfDB
9.显示并选择使用数据库NfDB
SHOW DATABASES
USE NfDB
10.创建删除数据库表
CREATE TABLE IF NOT EXISTS `MARIADB` (`NAME` VARCHAR(40) NOT NULL,`AGE` INT NOT NULL,PRIMARY KEY ( `NAME` ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
DROP TABLE MARIADB;
ALTER TABLE MARIADB DROP AGE;
ALTER TABLE MARIADB ADD ADDRESS VARCHAR(40) AFTER AGE;
ALTER TABLE MARIADB MODIFY ADDRESS CHAR(60);
ALTER TABLE MARIADB MODIFY AGE BIGINT NOT NULL DEFAULT 100;
11.修改表名
ALTER TABLE MARIADB2 RENAME TO MARIADB;
12.导出导入数据库表
```mysqldump -u root -p NfDB > NfDB.dump```
```mysql -u root -p NfDB < NfDB.dump```
三.使用客户端mysql查看系统中的数据库
*查看数据库名称*
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.001 sec)
*选中需使用数据库*
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
Database changed
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.001 sec)
MariaDB [mysql]>