Mysql Linux Command line Import .sql File

步骤:


1.链接mysql 指令如下


  mysql -u root -p 

  回车后输入 密码 再按回车,进入数据库

  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 37
  Server version: 5.6.21-log MySQL Community Server (GPL)

  Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.

  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


  看到上面的英文,就说明成功进入mysql 了

  show databases; 显示所有数据名称

  show engines;  显示数据库引擎  主要是看看数据库 是否支持自己 创建的 Innodb 或者 MyIsAm 引擎

 2.创建自己的数据库


   如下脚本创建数据库yourdbname,并制定默认的字符集是utf8。

   CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

  如果要创建默认gbk字符集的数据库可以用下面的sql:

    create database yourdb DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

3.使用自建数据库


   指令:use yourdbname;

4.ftp上传.sql 文件 


   我一般传在/alidata/www/default 目录下

5.利用source命令导入到刚刚创建的数据库中


 指令 source /alidata/www/default/db.sql

 看到下面执行语句表面 success !!!

 

6.查看已添加的数据表


 指令:show tables;


 完结。

 设置Mysql字符集防止中文乱码

 mysql> SET character_set_client = utf8 ;
 mysql> SET character_set_connection = utf8 ;
 mysql> SET character_set_database = utf8 ;
 mysql> SET character_set_results = utf8 ;
 mysql> SET character_set_server = utf8 ;
 mysql> SET collation_connection = utf8 ;
 mysql> SET collation_database = utf8 ;
 mysql> SET collation_server = utf8 ;


 SET NAMES 'utf8'; 相当于同时执行

 SET character_set_client = utf8;
 SET character_set_results = utf8;
 SET character_set_connection = utf8;







你可能感兴趣的:(Mysql)