7 May 18 Basic management of database related concepts (windows Mac) Basic SQL statement storage engine

7 May 18
1. Database related concepts
1. Two hardware expansion methods
   a. Vertical expansion: for one computer
   b. Horizontal expansion: multiple ordinary computers
   
2. Database related concepts
   Database server (essentially a computer on which the server of database management software is installed) -- referred to as database (operation and maintenance perspective)
   Database management system RDBMS (essentially a socket software with a C/S architecture) -- referred to as database (operation and maintenance perspective)
   Note: The server side of the general database management system is installed on the linux operating system
      mysqld——server; mysql——client (python can't use the server that comes with mysql, you need to use pymysql)
     a. Support concurrency
     b, lock problem
     c. Authenticate client requests
     d. Access efficiency (reduce the number of IOs)
   Library (folder) -- referred to as database (programmer's perspective)
   Table (file): fields to be set (header)
   Record: extract all typical features/data of a thing (a collection of a bunch of data)
     egon, 18,180, male, True
   data:
     name='egon' age=18 height=180 sex="male" beutiful=True
   SQL statement: The SQL statements used/defined by different database software are not exactly the same, but the difference is not big
 
3. Database management system/software classification DBMS:
   Relational RDBMS:
     There is a table structure, the table structure must be defined before accessing data, and the data must be stored according to the type or constraint of the field
     Typical representatives: MySQL, Oracle, DB2, SQL server (commonly used in the banking industry)
   Non-relational (commonly used by reptiles):
     Accessing data is in the form of key:value
Non-relational: Mongodb, redis, memcache (less commonly used)
 
2. Basic management (windows system)
1. Installation (installation is completed after the Windows system decompresses the file)
 
2. Add environment variables
 
3. Make mysqld software a system service
    Note: Turn off mysqld before making
    
    C:\Windows\system32>tasklist |findstr mysqld
    mysqld.exe                    8372 Console                    2    454,916 K
    C:\Windows\system32>taskkill /F /PID 8372
    Success: Process with PID 8372 terminated.
 
    Make:
        mysqld --install
    Check:
        windows + r
        Enter services.msc
 
4. Start:
   Unmade system service startup method:
     1. Start the server
        mysqld
 
     2. Start the client
        mysql -uroot -p -h127.0.0.1 -P 3306 #3306 is the default port for mysql
        If you log in to the mysqld server locally, you can abbreviate it: mysql -uroot -p #The local IP is known, and the port defaults
 
   After creating the system service, you can click the mouse to start or close mysql:
     windows + r
     Enter services.msc
     find mysql, start or close
 
5. Crack the administrator password
   1. First close the mysqld server
   2. Start the mysqld server on the command line by skipping the authorization table
      mysqld --skip-grant-tables
   3. The client directly logs in to the root user without a password and changes the password
      mysql -uroot -p
 
      mysql> update mysql.user set password=password("123") where user="root" and host="localhost";
      Query OK, 0 rows affected (0.00 sec)
      Rows matched: 1  Changed: 0  Warnings: 0
 
      mysql> flush privileges; #Force refresh after each change
      Query OK, 0 rows affected (0.00 sec)
 
   4. Kill the mysqld service with taskkill on the command line, and then start mysqld normally
      taskkill /F /PID 131312
 
      def password(mingwen): #password module can help encrypt plaintext, just call it directly
          import hashlib
          m=hashlib.md5()
          m.update(mimgwen)
          return m.hexdigest()
 
6. Unified character encoding
    1. Create a new my.ini file in the mysql installation directory
    2. Modify my.ini
        [mysqld]
        character-set-server=utf8
        collation-server=utf8_general_ci
 
        [client]
        default-character-set=utf8
 
        [mysql]
        default-character-set=utf8
 
    3. Restart mysqld
4. Client login, enter \s to view the results
 
3. Basic management (mac system)
1. Installation (mysql-5.6.35-macos10.12-x86_64.dmg)
 
2. Add environment variables
   https://blog.csdn.net/con_heart/article/details/53766931
 
   In fact, like windows, adding environment variables to the advanced properties is to find the command when you enter a command in any path, so you don't have to enter the file where the command is located every time you want to enter a command (such as logging in to mysql). Clip (usually quite long). The following is to add the path of the mysql command to the environment variable:
   1. Open the terminal and enter: cd ~
     will enter the ~ folder
 
   2. Then enter: touch .bash_profile
     After the carriage return is executed,
 
   3. Enter again: open -e .bash_profile
     will open the file in TextEdit (if no environment variables have been configured before, this should be a blank document). If there is content, please enter it before the terminator, if there is no content, please enter the following statement directly: export PATH=${PATH}:/usr/local/mysql/bin
     Then, save, quit TextEdit (must be quit), close the terminal and quit.
 
   4. Open the terminal again, directly enter [mysql -u "your user name" -p ], press Enter and enter the password. At this time, you can log in to mysql
 
3. View the mysql folder
   Go to the folder -> /usr/local/mysql
 
4. Start:
   Finder -> System Preferences
   PATH="$PATH":/usr/local/mysql/bin
   mysql -u root -p #-p do not add a space, directly connect to the password
 
5. Crack the administrator password
   https://blog.csdn.net/lishaojun0115/article/details/52805563
   
   step1: Apple -> System Preferences -> Click MySQL at the bottom to close the mysql service in the pop-up page (click stop mysql server)
   step2: Enter the terminal and enter: cd /usr/local/mysql/bin/
          After pressing Enter, log in with administrator privileges sudo su
          Enter the following command after pressing Enter to disable the mysql authentication function./mysqld_safe --skip-grant-tables &
          After pressing Enter, mysql will automatically restart (the status of mysql in the preferences will change to running)
 
   step3:
          Enter the command ./mysql
          After pressing Enter, enter the command FLUSH PRIVILEGES;
          After pressing Enter, enter the command SET PASSWORD FOR 'root'@'localhost' = PASSWORD('your new password');
 
   At this point, the password modification is completed, and you can log in successfully.
 
6. Unified character encoding (to prevent garbled characters, unified into utf-8)
   1. Copy the my.cnf file and add the following to it
   [mysqld]
   character-set-server=utf8
   collation-server=utf8_general_ci
   #basedir=/usr/local/mysql/
   #datadir=/usr/local/mysql/data/
   [client]
   default-character-set=utf8
   user=root
   password=******
   [mysql]
   default-character-set=utf8
   #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
 
   2. Close the mysql server
 
   3. Add my.cnf under \etc
 
   4. Restart the mysql server, log in to the client and view (\s)
 
7. Others:
   MAC computer to install Mysql server and Navicat for mysql client
   https://blog.csdn.net/kuangdacaikuang/article/details/76515985
 
Fourth, the basic SQL statement
#The main operation objects of SQL statements are libraries, tables, and records; among which operations on records are the most common
1. Folder (library) # The library name can be named according to the python naming rules
    increase
        create database db1 charset utf8;
    change
        alter database db1 charset gbk; #The library name cannot be modified
    check
        View library names of all libraries
        show databases; #where information_scheme is an in-memory table
        View information about a library alone
        show create database db1;
    delete
        drop database db1;
 
2. File (table) #Table name can be named according to python's naming rules
    First switch folders:
        use db1; #Can also be called by subsequent db1.t1
        select database(); #View the current folder
    increase
        create table t1(id int,name char); #char is str in sql
    change
        alter table t1 modify name char(16); #16 is the access limit, up to 16 characters can be accessed
    check
        View all table names under the current library
        show tables;
        View details of t1 table
        show create table t1;
        View table structure
        desc t1;
    delete
        drop table t1;
 
3. One line of the file (record)
    increase
        insert into db1.t1 values
        (1,'egon'), #Before adding, it is best to check the charset of the previous table
        (2,'alex'),
        (3,'lxx');
    change
        update db1.t1 set name='sb' where id > 1;
    check
        select id,name from db1.t1;
    delete
        delete from db1.t1 where name = "SB" ;
 
4, ; is the statement end prompt for the SQL statement
   \c If the statement is wrong, use it when you want to exit each input without affecting the result
 
5. Storage engine
#Thread pool used by Mysql

 
create table t1(id int)engine=innodb;
create table t2(id int)engine=myisam;
create table t3(id int)engine=blackhole;
create table t4(id int)engine=memory;
 

Common innodb, myisam, memory, blackhole several storage engines, the most commonly used is innodb innodb: also the default storage engine, supports transactions, row lock design, foreign keys

t1.frm (frame) t1.ibd (innodb data); save to hard disk

 

myisam: t2.MYD (myisam data) t2.MYI (myisam index) t2.frm (frame); save to hard disk

 

blackhole: t3.frm

 

memory: t4.frm; Stored in memory, after closing the server, the data is cleared

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325612552&siteId=291194637