64位ubuntu能安装mysql数据库_ubuntu安装mysql数据库教程

Ubuntu是一个比较流行的Linux操作系统,不仅简单易用,而且和Windows相容性非常好。那么在ubuntu下如何安装mysql数据库呢?

在Ubuntu上安装mysql数据库,一般分为两种方法,分别是使用Ubuntu Software Center或者apt命令来安装,而且过程都相对比较简单。

一、安装方式

1使用Ubuntu Software Center安装

打开Ubuntu Software Center,在右上角的搜索框查询mysql,然后选定MySQL Server,点击安装即可。

2使用apt命令安装

打开终端执行 ”sudo apt-get install mysql-server“ 即可。

二、MySQL初始配置

在成功安装mysql后,可以直接使用root账户登录,注意这个账户是默认没有密码的。因此为了数据库的安全,需要第一时间给root用户设置密码。

mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "";

将以上命令中的替换为你要设定的密码即可。设置密码后,如果再以root用户登录就需要输入密码了,如:

$ mysql -u rootERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)$ mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 75Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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 xavierERROR 1045 (28000): Access denied for user 'xavier'@'localhost' (using password: NO)$ mysql -u xavier -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 77Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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数据库进行操作了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值