• [javaEE] Ubuntu mysql 基本操作


    Ubuntu下载mysql 然后一些基本操作

    #登陆, -u是登陆名的意思, -p是密码
    sudo mysql -u root -p

    database操作

    查看有那些数据库
    show databases;

    创建数据库
    create database test_table;

    删除数据库
    drop database test_table;

    使用哪个数据库
    use testdatabases;

     table操作

    
    
    查看此数据库的表
    show talbes;

    创建表

    create table test_table (
      name varchar(20),
      year varchar(20),
      primary key (name)
    );
    查看表信息
    desc test_table;
    或者
    show create table test_table;


    修改表名
    alter table test1 rename as newtest1;

    表中增加列
    alter table test_table add column age varchar(20);


    表中删除列
    alter table test_table
    drop column age

      

     行列操作


    表中
    删除行
    delete from test_table where age=10;


    修改数据
    将十岁的改为十一岁
    update test_table set age=11 where age=10

    表中插入数据的方法
    insert into test_table
    (name, age)
    values
    ("张某", "18");


     

      

    插入中文会报错

    ERROR 1366 (HY000): Incorrect string value: 'xE7xBBx9FxE8xAExA1...

    默认编码方式是latin 需要修改为utf8

    #修改表的编码
    alter table test_table default character set utf8;
    
    #此时表的编码改了,但是列的编码依然为latin
    #查看表信息
    show create table test_table
    
    #根据列的要求修改列编码
    alter table test_table change name name varchar(50) character set utf8 not null;
    alter table test_table change age age varchar(50) character set utf8;

    查看端口号

    show global variables like 'port';

    增加自增属性

    给表box中的属性bid增加自增属性
    alter table box change bid bid int auto_increment;

    将sql导入mysql

    创建test数据库,并使用
    create database test;
    use test;
    
    导入 
    source 路径
    
    例如 source /opt/test.sql
  • 相关阅读:
    Mac下Selenium无法最大化Chrome解决方案
    Mac环境配置好ant后提示Permission denied
    禁止Chrome浏览器自动升级
    Selenium滚动条window.scrollTo和window.scrollBy
    Windows和Linux如何使用Java代码实现关闭进程
    自动化测试框架Selenium工作原理
    Mac下用SSH连接远程Linux或Mac服务器
    mac显示隐藏文件
    Selenium自动化测试脚本中三种等待时间简介
    Java虚拟机之栈
  • 原文地址:https://www.cnblogs.com/smuzoey/p/11241713.html
Copyright © 2020-2023  润新知