Msyql database
# forget your password
Vim / etc/my.cf
Add skip-grant-tables to [mysqld]
Restart Mysql
Now you can go directly to mysql and change the root password.
Execute the following command
USE mysql
UPDATE user SET Password = password ('new password') WHERE User = 'root'; updates the root password in the user table
Flush privileges
Delete the skip-grant-tables added in / etc/my.cf
Restart mysql and you will OK.
Specific operation of mysql
Log in
Mysql-h login host-u user name-p password
two。 Create a database
Create database database name character set gbk
Select the database to use: use database name
You can also choose directly when logging in: mysql-D database name-uroot-p
3. Create a database table
Create table table name (column declaration)
Take the creation of a transcript as an example, with the contents of student number (id), name (name), gender (sex) and grade (grade):
Create table student (
Id int unsigned not null auto_increment primary key
Name char (8) not null
Sex char (4) not null
Grade int unsigned null default "absent"
);
For some longer statements, you can write and save the statements as createtable.sql through any text editor, and execute the script through file redirection at the command prompt.
Mysql-D database name-uroot-p
< createtable.sql 语句解释: 括号内声明了4列内容, id、name、sex、grade为每列的名称, 后面跟的是数据类型描述, 列与列的描述之间用逗号(,)隔开; int指定该列的类型为int(范围为-83888608到83888607),在后面又有unsigned加以修饰,表示该类型为无符号类型,此时该列的取值为0到16777215; not null 表示该列值不能为空,必须填,如果不指定该属性,默认可为空; auto_increment 需在整数列中使用, 其作用是在插入数据时若该列为 NULL, MySQL将自动产生一个比现存值更大的唯一标识符值。在每张表中仅能有一个这样的值且所在列必须为索引列。 primary key 表示该列是表的主键, 本列的值必须唯一, MySQL将自动索引该列。 char(8)表示字符长度为8,tinyint取值范围是-127到128 加上unsigned就是0到255 用show tables;就可以查看记得表了 4.向表中插入数据 insert into student values(值1,值2,值3,值4...) 有时只需要插入部分数据 insert into student (列名1,列名2,列名3) values(值1,值2,值3) 5.查询表中数据 select 列名称 from 表名 [WHERE 查询条件] 例:查询所有人名字 select name from student; 查询所有人学号和姓名 select id,name from student; 查询所有内容 select * from student; 按条件查询 = < >! = isnot] null in like
Example: query the information of all the girls
Select * from student where sex = 'female'
Inquire about people with scores above 60 points
Select * from student where grade > 60
Inquire about the person surnamed Wang
Select * from student name like'% King%'
Query people whose id is less than 10 and whose score is greater than 60
Select * from stutdent where id60
6. Update the data in the table
Update table name set column name = new value where condition
Example:
Change the score from id 10 to 70
Update student set grade=70 where id=10
Change the name of id from Lu Jiangtao to 10 grade to 60.
Update student set id=10,grade=60 where name=' Lu Jiangtao'
7. Delete data from the table
Delete from table name where condition
Example:
Delete the line of id=2:
Delete from student where id=2
Delete score