MySQL常用命令和常见问题
MySQL常用命令和常见问题
--创建数据库并设置字符集create database wip default character set utf8 collate utf8_general_ci;-- 查看字符集变量show variables like 'character%';-- 备份数据库test到文件test.sqlmysqldump -uroot -pmax123 test > test.sql-- 恢复数据库mysql -uroot -pmax123 test < test.sql--注册系统服务,服务名缺省为mysqlmysqld --install [mysql_service_name]--注销系统服务mysqld --remove [mysql_service_name]--测试mysql -uroot -p--查看版本, 注意是大Vmysql -V--环境变量--可以新建一个MySQL的变量,PATH中加%MySQL%,如果有升级或者修改,这是最佳方式--MySQL = C:\Program Files (x86)\mysql-5.6.24\bin--修改密码mysqladmin -u root -p password newpassword
配置默认编码
my.ini中如下修改
windows下删除服务
sc delete mysql[SC] DeleteService 成功,需要重启
或者直接编辑注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services,删除服务后重启电脑
启动服务
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 tablealter 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
作者:CooMark
来源链接:https://www.cnblogs.com/wancy86/p/mysql.html
版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。
2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。