ubuntu 13.04 安装mysql数据库教程
我要评论2013/11/30 15:19:12 来源:绿色资源网编辑:www.downcc.com 评论:0点击:387次
Ubuntu是一个流行的Linux操作系统,基于Debian发行版和GNOME桌面环境,和其他Linux发行版相比,Ubuntu非常易用,和Windows相容性很好,非常适合Windows用户的迁移,预装了大量常用软件,中文版的功能也较全,支持拼音输入法,预装了firefox、Open Office、多媒体播放、图像处理等大多数常用软件,一般会自动安装网卡、音效卡等设备的驱动。
安装MySQL
在Ubuntu上可以使用Ubuntu Software Center或者apt命令来安装MySQL,两种方式都十分方便。
1. 使用Ubuntu Software Center:打开Ubuntu Software Center,在右上角的搜索框查询mysql,然后选定MySQL Server,点击安装即可。
2. 使用apt:打开终端执行 ”sudo apt-get install mysql-server“ 即可。
MySQL初始配置
MySQL完成安装后可以直接使用root账户登录,且该账户默认是没有密码的。注意这里的root角色就是指你的Ubuntu的root角色,如果你当前使用的系统帐号不是root的话,也不必切换到系统root账户,可以在登录MySQL的时候使用“-u"这个参数来指定登录账户。如:
$ mysql -u root
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> select Host, User from user;
+-----------+------------------+
| Host | User |
+-----------+------------------+
| 127.0.0.1 | root |
| ::1 | root |
| iUbuntu | |
| iUbuntu | root |
| localhost | |
| localhost | debian-sys-maint |
| localhost | root |
+-----------+------------------+
7 rows in set (0.00 sec)
因为此时root账户默认没有密码,所以不用输入密码就能以root角色登录并查看所有信息的权限。如果换成非root角色登录MySQL,则只拥有部分数据库操作权限。
$ mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
mysql> use mysql
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
因此MySQL完成安装后的第一件事就是给root用户设置密码,否则数据库将毫无安全可言。
mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "<password>";
将以上命令中的<password>替换为你要设定的密码,以上命令的意思是对在本机(localhost)使用<password>密码登录的root用户赋予所有数据库的操作权限。设置密码后,如果再以root用户登录就需要输入密码了,如:
$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 75
Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu)
Copyright (c) 2000, 2013, 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>
建立数据库独立用户
因为root用户拥有数据库的所有操作权限,所以不能轻易地提供给别人使用。在一个MySQL实例中可以创建多个数据库,这些数据库可能归属于不同项目,每个数据库的操作角色也不一样。对此可以针对不同那个数据库指定用户进行访问。
首先使用root角色创建一个数据库
mysql> create database db_web_monitor
然后将这个数据库授予一个叫xavier的用户使用
mysql> GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@localhost IDENTIFIED BY "xavier";
这样就可以使用xavier用户,密码为xavier在本机登录MySQL操作db_web_monitor数据库了。
$ mysql -u xavier
ERROR 1045 (28000): Access denied for user 'xavier'@'localhost' (using password: NO)
$ mysql -u xavier -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 77
Server version: 5.5.34-0ubuntu0.13.10.1 (Ubuntu)
Copyright (c) 2000, 2013, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db_web_monitor |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql>
开放远程登录权限
1. 首先修改MySQL的配置文件,允许监听远程登录。
$ sudo vi /etc/mysql/my.cnf
找到bind-address所在行
45 # Instead of skip-networking the default is now to listen only on
46 # localhost which is more compatible and is not less secure.
47 bind-address = 127.0.0.1
将 bind-address值修改为本机IP即可。
注意注释说明,如果是较老版本的MySQL,此处就应该是skip-networking,直接将其注释即可。
2. 授予用户远程登录权限。
mysql>GRANT ALL PRIVILEGES ON db_web_monitor.* TO xavier@"%" IDENTIFIED BY "xavier";
如此这般,xavier用户就可以在任意主机通过IP访问到本机MySQL,对db_web_monitor数据库进行操作了。
关键词:ubuntu,mysql,数据库
相关阅读
- 05-05ubuntu在vmware下的安装与配置
- 11-14Win7和Ubuntu12.04 双系统重装win7引导不见问题的解决方案
- 11-03Ubuntu重装启动失败进入修复grub rescue模式的解决方案
- 07-02用UNetbootin工具制作Ubuntu系统启动U盘
- 06-25ubuntu12.04安装tftp、配置tftp服务 错误解决方案
- 05-30Ubuntu 12.04 安装配置 Tomcat 7.0.40Tomcat 服务器
- 05-07UBuntu系统安装KVM创建虚拟机遭遇故障的解决办法
- 04-04ubuntu下安装了mysql 5 server忘记root密码怎么办?
- 04-04Ubuntu 11.0下配置Web服务器详细教程
- 04-04打破微软垄断笔记本安装Ubuntu9.04教程
阅读本文后您有什么感想? 已有 人给出评价!
用户评论
热门评论
最新评论
相关软件
热点图文
- 01-05mysql安装图解、mysql5.6.10安装详细图文教程
- 01-04Mysql 安装问题。提示MySQL Server 5.1 -- Error 1335.
- 11-22service mysql start出错,mysql不能启动,解决mysql: unrecognized service错误
- 01-11Can't connect to local MySQL server through socket '/tmp/mysql.sock'(2)
- 11-24wdcp修改mysql数据库root密码时提示原密码不对
- 05-13MySQL数据库INNODB 表损坏修复处理过程
- 07-18MySql5.0 Table错误:is marked as crashed and last (automatic?) repair failed
- 08-03如何查询mysql数据库中哪些表的数据量最大?
- 01-24MYSQL-Front中文版使用图文教程
- 04-04Win7系统安装MySQL5.5.21图解教程