您的位置:首页 > 数据库 > MariaDB

centos 下安装MariaDB 及其基本操作指令

2015-07-09 20:25 706 查看

<1>安装 MariaDB

[root@iZ236xzsl93Z ~]# sudo yum install MariaDB-server MariaDB-client
[root@iZ236xzsl93Z ~]# service mysql start
Starting MySQL. SUCCESS!


<2>MySQL操作

【restart】开启mysql:

# service mysql start
Starting MySQL SUCCESS!


【stop】关闭mysql

# service mysql stop


【restart】重新开启mysql

# service mysql restart

[root@iZ236xzsl93Z ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


#这个留在下一个博客中解决

运行mysql,root用户 不要登陆 默认没有密码

[root@iZ236xzsl93Z init.d]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.0.20-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


从mysql.user里面列出用户列表 密码

MariaDB [(none)]> SELECT user,host,password FROM mysql.user;


userhostpassword
rootlocalhost
rootiz236xzsl93z
root127.0.0.1
root::1
localhost
iz236xzsl93z
MariaDB [(none)]> show grants;


Grants for root@localhost
GRANT ALL PRIVILEGES ON . TO ‘root’@’localhost’ WITH GRANT OPTION
GRANT PROXY ON ”@’%’ TO ‘root’@’localhost’ WITH GRANT OPTION

MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS test;
Query OK, 1 row affected, 1 warning (0.00 sec)


【USE】进入test数据库

MariaDB [(none)]> USE test
Database changed
MariaDB [test]>


【CREATE TABLE】在test数据库中创建一个books表格

MariaDB [test]> CRERAT TABLE IF NOT EXISTS books(
-> BookID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> Title VARCHAR(100) NOT NULL,
-> SeriesID INT,
-> AuthorID INT );


【show】显示表格

MariaDB [test]> show tables;


Tables_in_test
authors
books
series

【describe】描述test表格

MariaDB [test]> describe books;


FieldTypeNullKeyDefaultExtra
BookIDint(11)NOPRINULLauto_increment
Titlevarchar(100)NONULL
SeriesIDint(11)YESNULL
AuthorIDint(11)YESNULL
【INSERT INTO】在books里面添加内容 格式:

—-Title,SeriesID,AuthorID

MariaDB [test]> INSERT INTO books (Title,SeriesID,AuthorID) VALUES('The Fellowship of the Ring,1,1),
->  ('The Two Towers',1,1), ('The Return of the King',1,1),  ('The Sum of All Men',2,2),
->  ('Brotherhood of the Wolf',2,2), ('Wizardborn',2,2), ('The Hobbbit',0,1);


【select】显示test里面的全部内容

MariaDB [test]> select * from books;


BookIDTitleSeriesIDAuthorID
1The Fellowship of the Ring11
2The Two Towers11
3The Return of the King11
4The Sum of All Men22
5Brotherhood of the Wolf22
6Wizardborn22
7The Hobbbit01

【insert】插入数据

MariaDB [test]> insert into  books (Title,SeriesID,AuthorID)
-> values ("Lair of Bones",2,2);
Query OK, 1 row affected (0.00 sec)
MariaDB [test]> select  * from books;


BookIDTitleSeriesIDAuthorID
1The Fellowship of the Ring11
2The Two Towers11
3The Return of the King11
4The Sum of All Men22
5Brotherhood of the Wolf22
6Wizardborn22
7The Hobbbit01
8Lair of Bones22

【update】修改test里面的第七个数据update

MariaDB [test]> update books set Title = "The Hobbit" where BookID = 7;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
MariaDB [test]> select * from books;


BookIDTitleSeriesIDAuthorID
1The Fellowship of the Ring11
2The Two Towers11
3The Return of the King11
4The Sum of All Men22
5Brotherhood of the Wolf22
6Wizardborn22
7The Hobbit01
8Lair of Bones22
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Mariadb linux centos-7