欢迎投稿

今日深度:

linux-mariadb,

linux-mariadb,


#################mariadb####
一.安装mariadb
1.yum install mariadb-server.x86_64 -y  systemctl start mariadb systemctl enable mariadb
2.查看mysql的端口是否开着,
[root@localhost ~]# netstat -antlpe |grep mysql
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      27         92219      3122/mysqld
####为了安全我们需要关闭该端口
vim /etc/my.cnf
      skip-networking=1
[mysqld_safe]
3.对mysql设置密码mysql_secure_installation按第一次回车后设置密码然后一直按回车直到完成。
4.登陆mysql有两种方式
方式一:mysql -uroot -p
方式二:mysql -uroot -predhat 后面直接加密码可以直接进入.
5.数据库的各种控制命令
1)MariaDB [(none)]> show databases;查看库信息如下
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

2)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
进入mysql数据库.用use可以切换数据库
3)show tables;查看数据库中的表信息.
4)desc user;查看表的格式
5)select * from user;查看表内信息
6)select * from user where Host='127.0.0.1';查看user表内值地址为127.0.0.1的信息
7)[root@localhost ~]# mysql -uroot -p -e "show databases;"从外面直接查看数据库命令

6.创建数据库与用户表.
MariaDB [(none)]> create database westos;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> use westos;
Database changed
MariaDB [westos]> create table linux (
    -> username varchar(50) not null,
    -> password varchar(50) not null,
    -> age varchar(4) );
Query OK, 0 rows affected (0.62 sec)

MariaDB [westos]> show tables;
+------------------+
| Tables_in_westos |
+------------------+
| linux            |
+------------------+
1 row in set (0.00 sec)
用户表的内部结构如下
MariaDB [westos]> desc linux;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(50) | NO   |     | NULL    |       |
| password | varchar(50) | NO   |     | NULL    |       |
| age      | varchar(4)  | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
MariaDB [westos]> insert into linux values ('qq','123','22');
Query OK, 1 row affected (0.04 sec)

MariaDB [westos]> select * from linux where age='22';
+----------+----------+------+
| username | password | age  |
+----------+----------+------+
| qin      | 123      | 22   |
| qq       | 123      | 22   |
+----------+----------+------+

7.修改表信息
1)MariaDB [westos]> alter table linux rename message;重命名
Query OK, 0 rows affected (0.04 sec)

MariaDB [westos]> use tables;
ERROR 1049 (42000): Unknown database 'tables'
MariaDB [westos]> use tables;
ERROR 1049 (42000): Unknown database 'tables'
MariaDB [westos]> show tables;
+------------------+
| Tables_in_westos |
+------------------+
| message          |
+------------------+
1 row in set (0.00 sec)
2)alter table message add class varchar(50) after password;添加一组表信息,放在password之后
3)salter table message drop class;删除掉class
4)update linux set class='linux';更新class中的内容
5)update linux set class='java' where username='lee';更新linux中uername为lee的class为java
8.备份
root@localhost ~]# mysqldump -uroot -predhat westos >/mnt/westos.sql把数据库备份到westos.sql
MariaDB [(none)]>drop database westos;删除数据库.
[root@localhost ~]# mysql -uroot -predhat -e "create database westos;"创建westos数据库,
mysql -uroot -predhat westos </mnt/westos.sql 把原先备份的东西备份到里面

9.删除
1)delete from linux where username='lee';删掉名字为lee的那一行表信息
2)delete from linux where username='lee' and class='java';删掉名字为lee的并且class为java的那一行信息
3)drop table message;删掉表message
4)drop database westos;删掉westos数据库;

www.htsjk.Com true http://www.htsjk.com/mariadb/29670.html NewsArticle linux-mariadb, #################mariadb#### 一.安装mariadb 1.yum install mariadb-server.x86_64 -y  systemctl start mariadb systemctl enable mariadb 2.查看mysql的端口是否开着, [root@localhost ~]# netstat -antlpe |grep mysql tc...
相关文章
    暂无相关文章
评论暂时关闭