In this article, I assumed that you can connect to mySQL server. I am about to describe some commands which are commonly used in MySQL.
MySQL is a open source database which is very world wide. THe language i am using here is English, because i want to preserve the meaning of the so called "techincal meaning".
Connect to and Disconnect from server
In order to connect to MySQL server, you are supposed to have a
user name and
password. If you are remotely connecting to server, certainly you have to have the
hostnameOnce you know all of them, you can connect to mySQL server by using this command:
mysql -u [username] -pEnter password: *********
If that information you entered are correct, you should see something like this:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 459 to server version: 3.22.12a-log
Type 'help' for help.
mysql>That prompt tells you that mysql is ready for your commands.
In order to quit from mySQL typing QUIT at that
mysql> prompt.
mysql>quit
ByeYou can also disconnect by pressing
Control-DThis section will be describing the very basic principles of entering command or
queries.
Here is the simple command that asks the server to tell you its version number and the current date. Typing it in as shown following the
mysql> prompt and press enter.
mysql>SELECT VERSION(), CURRENT_DATE;You will see a table that looks like:
|--------------|--------------------|
| VERIONS() CURRENT_DATE
|--------------|--------------------|
|3.22.20a-log 1999-03-19
|-----------------------------------|
1 row in set (0.01 sec)There are some conlcusions about the commands in mySQL
1. Commands must be end with a semicolon
( ; ). There were, however, some commands that don't need to be ended by
;, we will reach to them later.
2. mysql displays the result as a format of a table.
3. mysql does not concern whether the command is uppercase or lowercase. The following commands are the same:
SELECt VErsion(), CUrrent Date;
seLECT verSIon(), Current dATE;
select version(), current date;
Here is another query. It shows that you can use mysql as a simple calculator:
[b]mysql>select sin(pi/4), (4+1)*5;[/b]
You will see something like this:
|---------------|-------------|
SIN(pi/4) (4+1)*5
|-----------------------------|
0.707107 25
|-----------------------------|
You can even enter multiple commands on a single line. Just end each one with a semicolon
( ; ).
mysql> SELECT VERSION(); SELECT NOW();A command need not to be given all on a single line, so leghthy commands that require serveral lines are not a problem. mysql determines where your statement ends by looking for the terminating semicolon
( ; ). You can also do like this: (press enter after each line)
mysql> SELECT
->user()
->,
-> current date;[/i]
If you don't want to execute a command, cancel it by typing [i]\c:
mysql> SELECT
-> USER()
-> \c
mysql>In mysql, there are some prompts that contain their own meaning:
mysql> Ready for your command
-> Ready for next line of multiple line command
'> Ready for next line, collecting a string that begins with
'"> Ready for next line, collecting a string that begines with
"Creating and Using Database
In order to know what databases now you own, type this command:
mysql> SHOW DATABASES;As the result, you will see what datebases are under your control now.
If you are an adminstrator, you can access all databases from any users as well as an important database whose name is
mysql. That databases contain every information about users, host, privileges, databases......
If you are not an adminstrator, simply a user, you only can access your own databases and one databases whose name is
test.
Now, I assume you are a user. you can create database and the number of datebases you can create is depend on your plan of hosting. If you buy a plan of 3 Mysql, you can create 3 databases. By that way, you buy a plan of 30 Mysql, you can create up to 3 databases. Certainly, you are only accessible to your own databases not to others' databases.
In order to create databases, typing this command:
mysql> create database [data name];You want to test the existence of that database, use SHOW command again, you will see your created database.
In order to use a datase so that you can apply others commands, you have to type:
mysql>use [data name];Once when you use a datbase you can show tables from that datbase by using this command:
mysql>show tables;