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选项。否则创建的用户带密码。除非显示修改


注意,我这儿用的是123456做为root用户的密码,但是该密码是不安全的,请大家最好使用大小写字母与数字混合的密码,且不少于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来对xoops数据库进行管理,而无需要再用root用户了,而该用户的权限也只被限定在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 nameowner, and species columns because the column values vary in length. 


 

你可能感兴趣的:(数据库,mysql,Date,ubuntu,database,Deb)