Mysql 专题
专题目录
您的位置:database > Mysql专题 > ubuntu安装mysql数据库教程
ubuntu安装mysql数据库教程
作者:--    发布时间:2019-11-20

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 "<password>";

将以上命令中的<password>替换为你要设定的密码即可。设置密码后,如果再以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数据库进行操作了


推荐阅读:

ubuntu官方帮助文档

mysql教程


网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册