通过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
在Ubuntu下MySQL缺省是只允许本地访问的,如果你要其他机器也能够访问的话,那么需要改变/etc/mysql/my.cnf配置文件,改配置文件包括了mysql的一些基本配置,如端口等。
Mysql基本命令:(待续…..)