1. 首先用 sudo apt-get install mysql-server 命令去安装。 安装过程中,会让输入root帐号的密码,输2次; 安装成功后,会自动启动 mysql。
2. 配置MySQL
注意,在Ubuntu下MySQL缺省是只允许本地访问的,如果你要其他机器也能够访问的话,那么需要改变/etc/mysql/my.cnf配置文件了!下面我们一步步地来:
在ubuntu 本机上登陆mysql, 输入:
root@VM-136-26-ubuntu:~# mysql -u root -prootWelcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.5.38-0ubuntu0.12.04.1 (Ubuntu)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
然后再输入:
mysql> grant all privileges on *.* to root@"%" identified by “root” with grant option;
这行命令解释如下,*.*:第一个*代表数据库名;第二个*代表表名。这里的意思是所有数据库里的所有表都授权给用户。root:授予root账号。“%”:表示授权的用户IP可以指定,这里代表任意的IP地址都能访问MySQL数据库。“root”:分配账号对应的密码,这里密码自己替换成你的mysql root帐号密码。 密码要用双引号括起来。
最后再输入:
mysql>flush privileges;
这行命令是刷新权限信息,也即是让我们所作的设置马上生效。
3. 最后,我们就可以在远程机器上,用mysql 的客户端来连接 ubuntu上的mysql server了。