---
title: "mysql root 远程权限"
author: "夜鸣猪"
date: "2012-07-17T20:47:24Z"
tags: []
categories: ["编程语言"]
slug: "mysql-root"
draft: false
lastmod: "2012-07-31T00:10:44Z"
id: 1596823
url: "https://hlee.iteye.com/blog/1596823"
---

```java
sudo apt-get install mysql-server
```


Ubuntu installs Mysql at /etc/mysql/ by default. Now we need to set a root password.


```java
mysql -u root
mysql> SET PASSWORD FOR 'ROOT'@'LOCALHOST"
> = PASSWORD('new_password');
```


Now while we’re still here, we’ll create a new HOST for root and allow root to login from anywhere.


```java
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'
> IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit
```


Thanks to Thom for the Flush Privileges comment.  I think it depends on other settings in your MySQL setup, since I didn’t have to, but just in case, I’ve added it here.  We’re almost done now. We just have to tell Mysql to allow remote logins.


```java
sudo vi /etc/mysql/my.cnf
```


Out-of-the-box, MySQL only allows connections from the localhost identified by the IP Address of 127.0.0.1.  We need to remove that restriction, so find the line that says

```java

bind-address = 127.0.0.1
```


<span style="color:red">and comment it out</span>. That’s all there is to it! Now get your favorite MySql client and start developing.