关闭

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

标签: Mariadblinuxcentos-7
155人阅读 评论(0) 收藏 举报
分类:

<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;
user host password
root localhost
root iz236xzsl93z
root 127.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;
Field Type Null Key Default Extra
BookID int(11) NO PRI NULL auto_increment
Title varchar(100) NO NULL
SeriesID int(11) YES NULL
AuthorID int(11) YES NULL

【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;
BookID Title SeriesID AuthorID
1 The Fellowship of the Ring 1 1
2 The Two Towers 1 1
3 The Return of the King 1 1
4 The Sum of All Men 2 2
5 Brotherhood of the Wolf 2 2
6 Wizardborn 2 2
7 The Hobbbit 0 1

【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;
BookID Title SeriesID AuthorID
1 The Fellowship of the Ring 1 1
2 The Two Towers 1 1
3 The Return of the King 1 1
4 The Sum of All Men 2 2
5 Brotherhood of the Wolf 2 2
6 Wizardborn 2 2
7 The Hobbbit 0 1
8 Lair of Bones 2 2

【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;
BookID Title SeriesID AuthorID
1 The Fellowship of the Ring 1 1
2 The Two Towers 1 1
3 The Return of the King 1 1
4 The Sum of All Men 2 2
5 Brotherhood of the Wolf 2 2
6 Wizardborn 2 2
7 The Hobbit 0 1
8 Lair of Bones 2 2
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3178次
    • 积分:91
    • 等级:
    • 排名:千里之外
    • 原创:5篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档