Introduction and basic database operations

Introduction and basic database operations

1. randomly stored in a data file, the data format vary

2. Software Development db file directory folder, storing one file

I and II are read data locally

3. The store all data to a third party's public position, the same software all need to manipulate data, it is necessary to go to this shared position of the operation

Common position of third parties (database)

Database cluster: the same data in a database, copy to a different server

4.mysql data: cs software architecture

1) on the mysql database is essentially a software-based communications network

2) All the software-based network communication, are the underlying socket

Server:

Web-based communication

Send and receive messages

Client:

Web-based communication

Send and receive messages

All languages, if you want to go to operate the database, get the server ip and port, must comply with a standard set of instructions resolve the sql statement

DBSM: Database Management Systems

Relational Database:

mysql,oracle,db2,sqlserver。。。

Table Structure:

Which fields need

What type field

Fields and field types:

name - "string

age --- "integer

Non-relational databases:
Redis, MongoDB. . .

Non-relational databases generally key: value stored in the form

Install Database

1. Download the installation package mysql

2. Extract the installation package on D: in

3. Add the environment variable

4. to open an administrator cmd, enter mysqld start the server, this time will be the main card

mysql bin directory. exe file is started

5. When you create a cmd, mysql client server connection, enter the password mysql -h 127.0.0.1 -P

When no initialization mysql password, you can enter the tourist mode, the function will be very limited

No password direct access without a password

Enter the mysql server:

All written mysql -h 127.0.0.1 -P 3306 -p password

Shorthand mysql -uroot -p

password

6. Quit the database client

exit;

quit;

Note here that all the sql statements should be added at the end;

  • Check if the operating system has started mysqld server
    • tasklist | findstr "mysqld"

    • Kill the mysqld process
      • taskkill /F /PID pid号
    • ***** When doing server, you must first open an administrator

    • Database command:
      • View all databases:
        • show databases;
    • Production System Services
      • 1. started the mysqld server must be turned off
      • 2. Deletion has been started the mysqld process
      • 3. Enter mysqld --install ----> mysqld system installation services
      • 4. Enter net start mysqld
    • mysql mysql -u logon user name (root) -p password
      • The default comes with super user root, no password
      • Admin Login
        • Enter into mysql -uroot
      • Guest Sign
        • Enter mysql
    • change Password:
      • The default without a password, the password
        • cmd>>>: mysqladmin -uroot password 123
      • Under have a password, change passwords
        • cmd >>>: mysqladmin -uroot -p password password to modify the original password
        • cmd>>>: mysqladmin -uroot -p123456 password 123
    • Crack passwords: When using Password Forgot
      • 1. Turn off the server
      • 2. Skip permission to start the server
        • cmd>>>: mysqld --skip-grant-tables
      • 3. The client enters Guest mode:
        • cmd>>>: mysql

        • update mysql database table set field .user field password = password ( 'field value') where the condition (if the condition is satisfied, modifying) user = "root";
        • cmd>>>: update mysql.user set password=password('123456') where user="root";

      • 4. Restart the server, do not skip the certification authority
        • Skip to kill off the start of the certification authority server process
        • And then to manually open service mysql service to service
    • Set profile:
      • 1. In the first mysql directory - "D: \ mysql-5.6.40-winx64

      • 2. Create a file called "my.ini", this is mysql configuration file
        • [mysqld]
          character-set-server=utf8
          collation-server=utf8_general_ci

          This is the client software connected with python

          [client]
          default-character-set=utf8

          Mysql client-side software

          [mysql]

          Writable, so you can not write without a user name and password to log mysql

          user='root'

          password=123

          Set the default character encoding

          default-character-set=utf8

      • 3. Restart the mysql service, that amendment is successful!

    • The basic database operations:
      • Library operations ---> similar to folders
        • By:
          Syntax: create database database name;
          - the Create Database db1;

        • Check
          syntax: show databases; # View all the libraries
          show create database db1; # View information db1 library

        • Change the
          syntax: alter database library name charset = "character encoding type";
          - the ALTER Database db1 charset = "utf8";

        • Delete
          syntax: drop database db1;

      • Operating table ---> similar to a file
        • Before operating table, you need to switch to the specified database
          syntax: use database name;
          - use db1;

          View library is currently located: select database ()

        • By
          varchar and char is a string type;
          varchar (20 is)
          Syntax: create table table name (field name field type);
          Create Table USER_INFO (name varchar (20 is), Age int);

        • Charles
          show tables; # View all the tables in the current library
          desc user_info; # View table structure


        • 语法: alter table 表名 modify name varchar(28);
          - alter table user_info modify name varchar(28);

        • Delete
          syntax: drop table table name;
          - the Create the Table the Test (the above mentioned id int);
          - drop the Table the Test;

      • Recording operation ---> rows of similar data in the file
        • By:
          Syntax: insert into table values ( 'data field types 1', the field data type 1);
          # Insert an
          - insert into user_info values ( 'tank ', 17);

            # 插入多条
            - insert into user_info values('jason', 71), ('sean', 78);
        • Charles:
          : refers to all
          the syntax: the SELECT
          from table name; # to view the table all the data
          - select * from user_info;

            # 查看name 字段为 tank 的记录
                - select * from 表名 where 条件;  # 条件成立则查看成功!
                - select * from user_info where name="tank";
          
            # 查看name 字段为 tank 的age字段
                - select age from user_info where name="tank";
          
            # 查看所有的名字:
                - select name from user_info;
        • Change the
          syntax: update table set field name = field value where conditional; # if conditions are met, the amendment is successful!

            # 修改age为17的记录中name属性为 handsome
            - update user_info set name='handsome' where age=17;
          
            # 修改age>16的记录 中name属性为 d_sb
            - update user_info set name='d_sb' where age>16;
        • delete

          Syntax: delete from table name;
          # Empty Table record, not submission, recoverable.
          - delete from user_info;

          Syntax: truncate table table name;
          # delete, unrecoverable
          - truncate table user_info;

Guess you like

Origin www.cnblogs.com/godlover/p/12017104.html