Mysql-h192.168.137.10-uroot-p123
Mysql-uroot-p123
mysqladmin-uroot-p password "Redhat"
Mysqladmin-uroot-predhat password "123"
Grant all on * * to [e-mail protected] "%" identified by "Redhat";
MySQL -uzhang -predhat
Create DATABASE Luzhi default character set UTF8;
Create database luzhi1 character set UTF8;
Drop database Luzhi;
Drop database if exists luzhi1;
Create database if not exists luzhi444;
Drop database if exists luzhi444;
Use MySQL;
Show tables;
select * from user;
DESC user;
Select Database ();
Select version ();
Select DayOfMonth (current_date);
Mysql>use mytest;
Mysql> CREATE TABLE MyClass (
-ID Int (4) NOT null primary key auto_increment,
, name char (a) is not NULL,
, sex int (3) NOT null default 0,
-degree double (16,2));
mysql> INSERT INTO MyClass values (1, ' Tom ', 96.45), (2, ' Joan ', 82.99), (2, ' Wang ', 96.59);
SELECT * from MyClass;
SELECT * from MyClass ORDER by ID limit 0, 2;
Mysql> Delete from MyClass where id=1;
PHP Operation:
<?php
$con = mysql_connect ("localhost", "Peter", "abc123");
if (! $con)
{
Die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ("my_db", $con);
mysql_query ("DELETE from Persons WHERE lastname= ' Griffin '"); mysql_close ($con);
?>
mysql> Update MyClass set name= ' Mary ' where id=1;
Mysql> ALTER TABLE MyClass add passtest int (4) Default ' 0 ';
Mysql> Rename table MyClass to Youclass;
Create user [email protected] identified by '123456;
Grant Select on mydb.* to [email protected];
Drop user Guest;
Grant SELECT, INSERT, UPDATE, delete on new_db.* to [email protected]'%' identified by '88888888;
Example 1
Drop database if exists school; Delete if SCHOOL is present
Create Database School; Building a library SCHOOL
Use school; Open Library SCHOOL
CREATE TABLE teacher// Create tables teacher
(
ID int (3) auto_increment NOT null primary key,
Name Char (TEN) is not NULL,
Address varchar (+) default ' Shenzhen ',
Year Date
); End of Build table
The following is the Insert field
Insert into teacher values (",'Allen', ' Dalian One ' , ' 1976-10-10 - );
Insert into teacher values (",'jack', ' Dalian II ', ' 1975-12-23);
It is also possible to type the above commands at the MySQL prompt, but it is not easy to debug.
1, you can write the above command as is written in a text file, assuming that school.sql, and then copied to c:\\ , and in the DOS State into the directory [Url=file://\\mysql\\bin]\\mysql\\bin[/url], and type the following command:
Mysql-uroot-p Password < C:\\school.sql
If successful, empty a row without any display, and if there is an error, there is a hint. (The above command has been debugged, you can use it only if you remove // comment).
2, or enter the command line after using mysql> source c:\\school.sql; You can also add School.sql file into the database.
Example 2
Drop database if exists school; Delete if SCHOOL is present
Create Database School; Building a library SCHOOL
Use school; Open Library SCHOOL
CREATE TABLE teacher// Create tables teacher
(
ID int (3) auto_increment NOT null primary key,
Name Char (TEN) is not NULL,
Address varchar (+) Default ' Shenzhen ',
Year Date
); End of Build table
The following is the Insert field
Insert into teacher values (' ' ', ' Glchengang ', ' Shenzhen one ', ' 1976-10-10 ');
Insert into teacher values (' ' ', ' Jack ', ' Shenzhen one ', ' 1975-12-23 ');
Note: In the table under construction
1 . Set the ID to a numeric field of length 3 : Int (3); and let it automatically add one to each record : auto_ Increment; cannot be empty: not null; and let him be the main field primary key.
2 . Set NAME to a character field of length ten
3, the ADDRESS is set to the length of the character field, and the default value is Shenzhen.
4 . Set year as the Date field.
This article is from the "Tiandaochouqin" blog, make sure to keep this source http://luzhi1024.blog.51cto.com/8845546/1655472
MySQL Practice (Practice when you are free)