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

<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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值