本文主要是介绍在Linux中使用MySQL基础SQL语句及校验规则,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
卸载内置环境
查看是否存在MySQL
ps axj | grep mysql
关闭MySQL
systemctl stop mysqld
MySQL对应的安装文件
rpm -qa | grep mysql
批量卸载
rpm -qa | grep mysql | xargs yum -y remove
上传MySQL
rz
查看本地yum源
ls /etc/yum.repos.d/ -a
安装MySQL
rpm -ivh mysql57-community-release-el7.rpm
查看Linux版本
cat /etc/redhat-release
显示数据库show databases
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
/var/lib/mysql
会多一个目录。
创建
mysql> create database database1;
删除
mysql> drop database database1;
数据库的两个编码集
1.数据库编码集 数据库未来存储数据
2.数据库校验集 支持数据库,进行比较使用的编码,本质也是一种数据库中数据采用的编码方式。
数据库无论是对数据做任何操作,都必须保证操作和编码是一致的。
字符集和校验规则
查看系统默认字符集以及校验规则
show variables like 'character_set_database';
show variables like 'collation_database';
查看数据库支持的字符集
show charset;
查看数据库支持的字符集校验规则
show collation;
create database d1 charset=utf8 collate utf8_general_ci;
对其进行设置。
mysql> create database test1 collate utf8_general_ci;
mysql> create database test1 collate utf8_general_ci;
Query OK, 1 row affected, 1 warning (0.02 sec)
mysql> create database test2 collate utf8_bin;
mysql> create database test2 collate utf8_bin;
Query OK, 1 row affected, 1 warning (0.02 sec)
mysql> create table person(name varchar(20));
不区分大小写 utf8_general_ci
mysql> select * from person where name='a';
+------+
| name |
+------+
| a |
| A |
+------+
区分大小写 utf8_bin
mysql> use test2
Database changed
mysql> create table person(name varchar(20));
Query OK, 0 rows affected (0.06 sec)
mysql> insert into person (name) values ('a');
Query OK, 1 row affected (0.01 sec)
mysql> insert into person (name) values ('A');
Query OK, 1 row affected (0.02 sec)
mysql> select * from person where name='a';
+------+
| name |
+------+
| a |
+------+
显示
mysql> show tables;
+-----------------+
| Tables_in_test1 |
+-----------------+
| person |
+-----------------+
1 row in set (0.01 sec)
desc
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.01 sec)
select (DQL)
mysql> select * form person;
插入
mysql> insert into person (name) values ('D');
order by
mysql> select * form person order by name;
这篇关于在Linux中使用MySQL基础SQL语句及校验规则的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!