Some operations of mysql on Linux 2018.4.24

Install mysql: yum -y install mysql
                   yum -y insatll mysql-server
start mysqld: service mysqld start

Create database (on Linux command line): mysql -hlocalhost -uroot -p123456
                               -h: database host -u: user -p: password
Exit mysql: exit or quit

 


mysql database import and export command
      under linux 1. First, check the mysql related directory under linux
                 root@ubuntu14 :~# whereis mysql
                        mysql:
                        /usr/bin/mysql---- mysql running path
                        /etc/mysql
                        /usr/lib/mysql ----- mysql installation path
                        /usr/bin/X11/mysql
                        /usr/share/mysql
                        /usr/share/man/man1/mysql.1.gz
              There is another one:
                         var/lib/mysql --- -----The storage path of the mysql database data file
       2. Determine the running path, and execute the import and export mysql database commands
1. Use the mysqldump command to export the database
       (note: cd to the running path of mysql, and then execute the command) :
1. Export data and table structure:
        mysqldump -u username -p password database name > database
        name.sql mysqldump -uroot -p dbname > dbname .sql
       After pressing Enter, you will be prompted to enter a password
2. Only export the table structure
          mysqldump -u username -p password -d database name > database
          name.sql mysqldump -uroot -p -d dbname > dbname .sql

2. Import the database
1. First create an empty database
         mysql>create database dbname;
     delete the database:
         mysql > drop databases database name;
2. Import the database
Method 1:
 (1) Select the database
            mysql>use dbname;
 (2) Set the database code
             mysql >set names utf8;
 (3) Import data (pay attention to the path of the sql file)
             mysql>source /home/xxxx/dbname .sql;
Method 2:
    mysql -u username -p password database name < database name.sql

3. View the general_log_file of the mysql log
: mysql>show VARIABLES like '%general_log%';

Set path: mysql > set global general_log_file='/tmp/general.lg'; (set path)
    mysql> set global general_log=on; (# turn on general log mode)
   mysql> set global general_log=off; (# turn off general log mode)
           --- these changes will disappear after mysql is shut down and restarted, and there are always configuration files that need to be modified for mysql


4. Table
1. Create table
mysql>user database name
         > create table name( create table
          -> id int auto_increment not null primary key ,
          -> uname char(8),
          -> gender char(2),
          -> birthday date ) ;
Query OK, 0 rows affected (0.03 sec)
View: mysql>show tables;
2. Delete the table
drop table table name
3. View the data in the table
mysql > show columns from student;
4. View the records in the table (specific values)
mysql > select id, uname, gender from student;
 5. Insert records into
mysql > insert into test.student values(1,'a',11);
In Linux: mysql -uroot -p123456 -e "insert into test.student values(1,'a',11);"
 6. Clear the data in the table
mysql >delete from 表名
 7. Delete some data in the table
mysql > delete from table name where expression (for example: id=1)

Guess you like

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