MySQL database acquaintance (base statement)

Acquaintance Mysql

Cognitive

数据库:DB
    所有的数据存放的仓库
    每一个文件夹也是数据库
数据库管理员:DBA
    管理数据库软件
数据库服务器:一台跑着一个数据库管理软件的机器
表:文件,一张存储了数据的表    
数据/记录:表中的信息,一行就是一条记录

Learn Mysql

Database management software classified --DBMS

Relational database table structure needs to have
a non-relational database is a key-value store, the table structure is not

关系型数据库:如sqllite,db2,oracle,access,sql server,MySQL,注意:sql语句通用
非关系型数据库:mongodb,redis,memcache

Environment Variables

python —>python.exe

Python.exe file can be found in any directory

Enter the command to start the python interpreter python in any position

  • mysqld install install mysql service mysql service was registered with the operating system
  • net start mysql start mysql service
  • net stop mysql service mysql stop

-sudo mysql.server stop stop the MySQL service
-sudo mysql.server restart to restart the MySQL service
-sudo mysql.server status to view the status of MySQL services

Start the client connects to the server end

mysql -uroot -p123 -h192.168.14.12 telnet < '- h'>

mysql> select user (); view the current logged-on user

mysql> set password = password ( '123'); set a password for the current user

Creating a user other

create user 'guest'@'192.168.14.%' identified by '123';

To a user authorization

. Grant permission type on ftp * to 'guest'@'192.168.14.%';

grant all

grant select on day37.* to 'guest'@'192.168.14.%';

grant select,inster

#进入mysql客户端
$mysql
mysql> select user();  #查看当前用户
mysql> exit     # 也可以用\q quit退出

# 默认用户登陆之后并没有实际操作的权限
# 需要使用管理员root用户登陆
$ mysql -uroot -p   # mysql5.6默认是没有密码的
#遇到password直接按回车键
mysql> set password = password('root'); # 给当前数据库设置密码

# 创建账号
mysql> create user 'eva'@'192.168.10.%'   IDENTIFIED BY '123';# 指示网段
mysql> create user 'eva'@'192.168.10.5'   # 指示某机器可以连接
mysql> create user 'eva'@'%'                    #指示所有机器都可以连接  
mysql> show grants for 'eva'@'192.168.10.5';查看某个用户的权限 

# 给账号授权
mysql> grant all on *.* to 'eva'@'%';
mysql> flush privileges;    # 刷新使授权立即生效

# 创建账号并授权
mysql> grant all on *.* to 'eva'@'%' identified by '123' 

# 用户相关操作
# 查看当前用户是谁? select user();
# 给当前用户设置密码 set password = password('123');
# 创建用户 create user '用户名'@'主机的ip/主机域名' identified by '密码'
# 授权 grant select on 数据库名.* to '用户名'@'主机的ip/主机域名' identified by '密码'
# 授权并创建用户 grant select on 数据库名.* to '用户名'@'主机的ip/主机域名'

Database operations

  • View all databases show databases;
  • Create a database create database database name;
  • Switch to the name of this library use the database
  • How many tables show tables next to see this library;

Operating Table

- View all the tables show tables at the library;

- Create a table

create table table name (field data type (length), Field Name Data Type (length), ..);
create table Student (name char (12 is), Age int);

- Delete a table drop table table name;

- View table structure desc table name // describe table name

Operating data

  • Insert data

    insert into table values ​​(data line), (line data) (data line);

    insert into table (field, ...) values ​​(row of data, ...);

  • delete data

    delete from table where conditions;

  • change the data

    update table set field = value, the value of field 2 = 2 WHERE condition;

  • Query data

    select fields (*) from table name;

Operating databases, tables, content summary

1. 操作文件夹(库)
   增:create database db1 charset utf8;
   查:show databases;
   改:alter database db1 charset latin1;
   删除: drop database db1;


2. 操作文件(表)
   先切换到文件夹下:use db1
   增:create table t1(id int,name char);
   查:show tables;
   改:alter table t1 modify name char(3);
      alter table t1 change name name1 char(2);
   删:drop table t1;
    

3. 操作文件中的内容(记录)
   增:insert into t1 values(1,'egon1'),(2,'egon2'),(3,'egon3');
   查:select * from t1;
   改:update t1 set name='sb' where id=2;
   删:delete from t1 where id=1;

   清空表:
       delete from t1; #如果有自增id,新增的数据,仍然是以删除前的最后一样作为起始。
       truncate table t1;数据量大,删除速度比上一条快,且直接从零开始,

Additional ip

# ip和域名
# 搜索的机器
# 10.125.23.1  sogou.search01.org
# 10.125.23.2  sogou.search02.org
# 10.125.23.3  sogou.search03.org
# 10.125.23.4  sogou.search04.org
# 浏览器
# 10.135.24.7
# 10.135.24.8
# 10.135.24.9
# 10.135.24.10
#
# www.baidu.com 136.17.2.2

Guess you like

Origin www.cnblogs.com/shuai-jie/p/11204197.html