MySQL Introduction
rpm Linux 。 –ivh , i rmp ,V ,h “#” 。 。
Ubuntu RPM
Ubuntu deb, rpm , alien rpm deb。
sudo apt-get install alien #alien ,
sudo alien xxxx.rpm # rpm deb, xxxx.deb
sudo dpkg -i xxxx.deb #
MySQL
sudo apt-get install mysql-server
MySQL
, Ubuntu MySQL , , /etc/mysql/my.cnf ! :
MySQL , :
$mysql -u root
-u root (firehare), -u root ,mysql firehare
mysql , Mysql root , ,Mysql 。
mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456"; // root , *.*; // , "123456" identified 。 。
、 はここでrootユーザーのパスワードとして123456を していますが、このパスワードは ではありません. と と を ぜたパスワードを したほうがいいです.8 です.これでMySQLのrootユーザーパスワードが され、rootユーザーで なデータベースが されます.ここではxoopsを に げます:mysql>CREATE DATABASE xoops; mysql>GRANT ALL PRIVILEGES ON xoops.* TO xoops_root@localhost IDENTIFIED BY "654321";これでxoops_が されましたrootsのユーザーは、データベースxoopsにすべての を っています. でxoops_を いますrootは、rootユーザを する がなく、xoopsデータベースを します.このユーザの もxoopsデータベースに されます.リモートアクセスまたは を う は、mysql>GRANT ALL PRIVILEGES ON xoops.*TO xoops_root@"%"IDENTIFIED BY "654321";xoopsを rootユーザーは のマシンからMySQLに できます.%は に することを すが、この が する がある は、どこに があるか からないように する. つ は$sudo gedit/etc/mysql/my.cnfの しいバージョンでは、>bind-address=127.0.0.1=>bind-address=あなたのマシンのIPで、 のマシンがMySQLにアクセスできるようになりました.bindはバインディングの IPを す On Unix, to install a compressed tar file binary distribution,
unpack it at the installation location you choose (typically
/usr/local/mysql). This creates the directories shown in the
following table.
shell> mysql ; , ,
mysql> SHOW DATABASES;
mysql> USE test
USE
, like QUIT
, does not require a semicolon. (You can terminate such statements with a semicolon if you like; it does no harm.) The USE
statement is special in another way, too: it must be given on a single line.
mysql> QUIT
mysql> SELECT VERSION(), CURRENT_DATE;
+--------------+--------------+
| VERSION() | CURRENT_DATE |
+--------------+--------------+
| 5.5.0-m2-log | 2009-05-04 |
+--------------+--------------+
1 row in set (0.01 sec)
mysql>
Keywords may be entered in any lettercase. The following queries are equivalent: mysql> SELECT VERSION(), CURRENT_DATE;
mysql> select version(), current_date;
mysql> SeLeCt vErSiOn(), current_DATE;
Here is another query. It demonstrates that you can use mysql as a simple calculator: mysql> SELECT SIN(PI()/4), (4+1)*5;
+------------------+---------+
| SIN(PI()/4) | (4+1)*5 |
+------------------+---------+
| 0.70710678118655 | 25 |
+------------------+---------+
1 row in set (0.02 sec)
mysql> SELECT VERSION(); SELECT NOW();
A command need not be given all on a single line, so lengthy commands that require several lines are not a problem.
Here is a simple multiple-line statement:
mysql> SELECT
-> USER()
-> ,
-> CURRENT_DATE;
+---------------+--------------+
| USER() | CURRENT_DATE |
+---------------+--------------+
| jon@localhost | 2005-10-11 |
+---------------+--------------+
If you decide you do not want to execute a command that you are in the process of entering,cancel it by typing\c
: されたが された をキャンセルします.mysql> SELECT
-> USER()
-> \c
mysql>
Here, too, notice the prompt. It switches back to mysql>
after you type \c
, providing feedback to indicate thatmysql is ready for a new command.
Prompt
Meaning
mysql>
Ready for new command.
->
Waiting for next line of multiple-line command.
'>
Waiting for next line, waiting for completion of a string that began with a single quote (“'
”).
">
Waiting for next line, waiting for completion of a string that began with a double quote (“"
”).
`>
Waiting for next line, waiting for completion of an identifier that began with a backtick (“`
”).
/*>
Waiting for next line, waiting for completion of a comment that began with /*
.
In MySQL, you can write strings surrounded by either “'
” or “"
” characters
mysql> SHOW DATABASES;
SELECT
DATABASE()
.
SHOW DATABASES
does not show databases that you have no privileges for if you do not have the SHOW DATABASES
privilege.
+----------+
| Database |
+----------+
| mysql | (mysql )
| test |
| tmp |
+----------+
The mysql
database describes user access privileges. The test
database often is available as a workspace for users to try things out. mysql> USE test
Database changed
USE
, like QUIT
, does not require a semicolon. (You can terminate such statements with a semicolon if you like; it does no harm.) The USE
statement is special in another way, too: it must be given on a single line.mysql> CREATE DATABASE menagerie;
shell> mysql -h host
-u user
-p menagerie
Enter password: ********
mysql> SHOW TABLES;
mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
-> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
VARCHAR
is a good choice for the name
, owner
, and species
columns because the column values vary in length.