zoukankan      html  css  js  c++  java
  • MySQL常用命令和常见问题

    MySQL常用命令和常见问题

    --创建数据库并设置字符集
    create database wip default character set utf8 collate utf8_general_ci;
    
    -- 查看字符集变量
    show variables like 'character%';
    
    -- 备份数据库test到文件test.sql
    mysqldump -uroot -pmax123 test > test.sql
    
    -- 恢复数据库
    mysql -uroot -pmax123 test < test.sql
    
    --注册系统服务,服务名缺省为mysql
    mysqld --install [mysql_service_name]
    
    --注销系统服务
    mysqld --remove [mysql_service_name]
    
    --测试
    mysql -uroot -p
    
    --查看版本, 注意是大V
    mysql -V
    
    --环境变量
    --可以新建一个MySQL的变量,PATH中加%MySQL%,如果有升级或者修改,这是最佳方式
    --MySQL = C:Program Files (x86)mysql-5.6.24in
    
    --修改密码
    mysqladmin -u root -p password newpassword
    
    

    配置默认编码

    my.ini中如下修改

    windows下删除服务

    sc delete mysql
    [SC] DeleteService 成功,需要重启
    

    或者直接编辑注册表HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServices,删除服务后重启电脑

    启动服务

    net start MySQL
    

    外键
    外键必须是parent表的主键/unique 字段,否则添加不成功

    --ERROR 1215 (HY000): Cannot add foreign key constraint
    --类似primary key的设置方式
    foreign key (user_id) references user (id) on delete cascade
    --建表后alter table
    alter table team_member add constraint fk_team_member_user_id foreign key (user_id) references user (id) on delete cascade;
    

    By the SQL standard, a foreign key must reference either the primary key or a unique key of the parent table. If the primary key has multiple columns, the foreign key must have the same number and order of columns

  • 相关阅读:
    10_SpringBoot集成TkMybatis插件
    Mysql-YUM安装
    docker数据拷贝
    jquery实现倒计时功能
    CentOS 7.2使用源码包编译安装MySQL 5.7.22及一些操作
    vue中开发webSocket
    YARN 与Maprd 配置
    js实现轮播图2
    DOM
    js五星好评
  • 原文地址:https://www.cnblogs.com/wancy86/p/mysql.html
Copyright © 2011-2022 走看看