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

  • 相关阅读:
    最牛B的编码套路
    查看端口号
    一个电脑 两个显示屏
    如何修改报表平台中数据决策系统登陆地址
    MTK+Android编译
    报表参数控件和报表内容自动居中设置方法
    如何把报表放到网页中显示(Web页面与报表简单集成例子)
    报表与微信公众号(企业号)集成方案
    在开发过程中调试报表插件详细教程
    电量检测芯片BQ27510使用心得
  • 原文地址:https://www.cnblogs.com/wancy86/p/mysql.html
Copyright © 2011-2022 走看看