Home > Database > Mysql Tutorial > Introduction to MySQL

Introduction to MySQL

零下一度
Release: 2017-07-27 15:53:11
Original
1190 people have browsed it

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
    Copy after login
  • Display database command

    show databases;
    Copy after login
  • Create database command

    create database 数据库名;
    Copy after login
  • Delete database command

    drop database 数据库名;
    Copy after login
  • Switch the current database

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

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

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

    set names utf8;
    Copy after login
  • 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;
    Copy after login

    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;
    Copy after login

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

    Related labels:
    Statement of this Website
    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
    Latest Issues
    MySQL stops process
    From 1970-01-01 08:00:00
    0
    0
    0
    Error when installing mysql on linux
    From 1970-01-01 08:00:00
    0
    0
    0
    phpstudy cannot start mysql?
    From 1970-01-01 08:00:00
    0
    0
    0
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template