Mysql基本命令

来源:互联网 发布:wan端口断开 编辑:程序博客网 时间:2024/06/07 01:15
rpm -e  --nodeps mysql   #强制删除mysql及依赖文件
yum install mysql.x86_64 mysql-server.x86_64
service mysqld start
mysqladmin -u root password 1234  #创建数据库密码
mysqladmin -u root -p password "test123" #修改密码
Enter password: 【输入原来的密码】
mysql -u root -p  #密码登陆数据库
mysql -u root -h 192.168.1.181 -p #登陆远程主机
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION;  #开启远程查询
system clear;  #系统清屏命令
create table test (no char(9),name char(10),age smallint)
select * from 表名; #查看表
drop table test;   #删除表
insert into test (no,name,age) values ( '01' , 'wangcou' ,22); #插入记录
alter table test add city char(7) not null default ‘baoding‘; #添加表结构
alter table test drop column city;  #删除表结构
select * from test where age > 22;  #条件查询
降序select * from test order by age desc;
升序 select * from test order by age asc;
update test set age=age+1;  #表更新
alter table test add primary key (no) #设定表主键
表的备份与还原
mysqldump -u root -p1234 haha > /opt/haha.db #数据迁移与备份
create haha;
use haha;
source /opt/haha.db  #数据恢复
mysqldump -u root -p1234 haha test > /home/test.sql  #导出数据库中的某个表

0 0
原创粉丝点击