mysql日常操作命令-持续更新

mysql 忘记ROOT密码修改
 

# server mysql5 stop 
# mysql_safe --skip-grant-table&  跳过授权 
# mysql 
将密码改成123456 记住要password('123456') 这样的形式,因为密码要加密的。
mysql> UPDATE user SET password=password('123456') WHERE user='root';  
mysql> FLUSH PRIVILEGES; 使其生效
#server mysql5 restart
# mysql -u root -p123456  登入 
 
一次删除多条记录的两种方法,第一种在。。。。之间,第二种选择你要删除的
mysql> delete from kkk where id between 3 and 4;
mysql> delete from kkk where name in ("wang","zhang");

mysql 建立表例子:

 mysql> create table company (
    -> id int not null auto_increment primary key,
    -> name char(10),
    -> job char(20),
    -> location varchar(30),
    -> time date);
Query OK, 0 rows affected (0.00 sec)
 
利用shell 插入多条记录
# mysql -uroot -e "insert into ms.company(name,job,location,time) values ('alex','enginer','guangdong',now());"

上面是在shell里面插入记录,我们通过一个批量脚本来插入500条数据:
n=wname
i=1
while [ $i -lt 500 ]
do
#echo "$n$i"
mysql -uroot -e "insert into ms.company(name,job,location,time) values ('$n$i','enginer','guangdong',now());"
i=`expr $i + 1`
done

删除一个范围内的数据,delete from company where id between 502 and 543;
更新数据 update company set name='tom',location='hainan' where id = 2;
 

你可能感兴趣的:(数据库,mysql,职场,休闲)