现在的位置: 首页 > 综合 > 正文

Ubuntu mysql安装和配置

2012年10月31日 ⁄ 综合 ⁄ 共 1206字 ⁄ 字号 评论关闭

通过apt-get install命令可以很快的安装:

 

$sudo apt-get install mysql-server

 

 

ubuntu的安装过程会让你输入一个密码。密码对应的root账户。

配置 MySQL 的管理员密码

 

$ sudo mysqladmin -u root password newpassword

 

一旦安装完成,MySQL 服务器应该自动启动。您可以在终端提示符后运行以下命令来检查 MySQL 服务器是否正在运行:

 

$sudo netstat -tap | grep mysql

 

登录数据库:

 

sudo mysql –u root -p

 

输入该命令后会提示输入root密码,输入后就可进入操作命令行了。

yblin@yblin-desktop:/bin$ mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or /g.

Your MySQL connection id is 56

Server version: 5.0.75-0ubuntu10.2 (Ubuntu)

 

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

 

mysql>

 

在操作命令行下面输入sql语句执行,sql语句后面跟分号结束。。

如要查询当前的mysql版本的时间:

 

yblin@yblin-desktop:/bin$ mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or /g.

Your MySQL connection id is 56

Server version: 5.0.75-0ubuntu10.2 (Ubuntu)

 

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

 

mysql> select version(), current_date;

+--------------------+--------------+

| version()          | current_date |

+--------------------+--------------+

| 5.0.75-0ubuntu10.2 | 2009-10-27   |

+--------------------+--------------+

1 row in set (0.00 sec)

 

在命令行下面就可以进行增删改查等操作。具体的命令查看手册。

 

 

如果服务不能正常启动,通过下面命令启动:

sudo /etc/init.d/mysql restart

 

UbuntuMySQL缺省是只允许本地访问的,如果你要其他机器也能够访问的话,那么需要改变/etc/mysql/my.cnf配置文件,改配置文件包括了mysql的一些基本配置,如端口等。

 

Mysql基本命令:(待续…..)

 

 

抱歉!评论已关闭.