您的位置:首页 > 数据库 > MySQL

Ubuntu16.04 MySQL的安装及设置数据库编码为UTF-8

2018-01-03 22:29 597 查看
查看MySQL是否安装

      netstat –tap | grep mysql

安装MySQL  默认安装不是utf-8码,所以需要下面的设置

      sudo apt-get install mysql-server mysql-client

      输入root用户密码

测试是否安装成功

      netstat –tap | grep mysql 

基本操作

登录MySQL   mysql –u root –p

退出MySQL    quit;

查看当前数据库   show databases;  

创建数据库test    create database test; 

选择test数据库    use test;  

显示当前数据库中的表  show tables;

建表create table student(

      -> id int not nullprimary key,

      -> name char(8),

      -> age char(8),

      -> birthday date );

显示数据库表的结构    describe 表名;

删库   drop test;

删表   drop table 表名;

设置MySQL数据库编码为UTF-8

 登陆后查看数据库当前编码:SHOW VARIABLES LIKE 'character%';

 修改/etc/mysql/my.cnf (默认安装路径下) (标签下没有的添加,有就直接修改)

     [mysqld]

     character_set_server=utf8

     [mysql]

     default-character-set= utf8

     [client]

     default-character-set = utf8

重启MySQL服务 service mysql restart

查看数据库编码:SHOW VARIABLES LIKE 'character%';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: