Home  >  Article  >  Database  >  Introduction to MySQL

Introduction to MySQL

零下一度
零下一度Original
2017-07-27 15:53:111113browse

Simple use of MySQL

  1. Use the MySQL command line tool

  • For Windows users: MySQL Client, enter password

  • Linux:

    mysql -u用户名 -p密码
    mysql -uroot -p
  • Display database command

    show databases;
  • Create database command

    create database 数据库名;
  • Delete database command

    drop database 数据库名;
  • Switch the current database

    use 数据库名
    use mysql
  • Display all tables in the current database

    show tables;
  • Create table statement, create a table in the current database

    create table 表名 (列的声明...)
  • Set the encoding of the current command line window: Set the text encoding of the current window to UTF-8

    set names utf8;
  • Execute sql script command: Execute a batch of SQL commands in the text file.

    Please note: Be sure to know the path and ensure the path Correctness!!!

    • If the SQL file is UTF-8 encoded, you must first execute set names utf8;

      source text File path name;
      source D:\Robin\Note\note_ziliao\cloud_note.sql
      source /home/soft01/note_ziliao/cloud_note.sql

    Case: Execute the script to create a data table:

    source /home/soft01/note_ziliao/cloud_note.sql
    show databases;
    use cloud_note;
    show tables;

    Case: Create a table and insert data.

    create database demo;
    use demo
    create table MyTable(id int, name varchar(100));
    insert into MyTable (id, name) values (1, 'Tom');
    insert into MyTable (id, name) values (2, 'Jerry');
    select id, name from MyTable;
    drop table MyTable;
    drop database demo;

    The above is the detailed content of Introduction to MySQL. For more information, please follow other related articles on the PHP Chinese website!

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Previous article:DDLNext article:DDL