Home >Database >Mysql Tutorial >ubuntu下mysql的一些相关常用命令_MySQL

ubuntu下mysql的一些相关常用命令_MySQL

WBOY
WBOYOriginal
2016-06-01 13:11:48945browse

Ubuntu

查看mysql状态,是否启动
service --status-all

查看所有服务的状态: 

service --status-all

启动mysql:

方式一:sudo /etc/init.d/mysql start  方式二:sudo start mysql 方式三:sudo service mysql start

关闭mysql:

方式一:sudo /etc/init.d/mysql stop  方式二:sudo stop mysql 方式san:sudo service mysql stop

重启mysql:

方式一:sudo/etc/init.d/mysql restart 方式二:sudo restart mysql 方式三:sudo service mysql restart

ubuntu下mysql不能远程连接数据库的问题:

一般安装好mysql后,自带的用户角色是只限制在本机连接该mysql。可通过mysql数据库下的user表中查看该信息:

mysql> use mysql;Database changedmysql> select user,host from user;+-------+-----------+| user  | host      |+-------+-----------+| root  | 127.0.0.1 || root  | ::1       || root  | localhost |+-------+-----------+4 rows in set (0.04 sec)

可以看到root用户只限制在本机连接mysql。

我们最好新创建一个用户,并指定其权限可通过远程主机访问该mysql

create user 'admin'@'%' identified by 'password';

授权:

grant all on *.* to 'admin'@'%'

再查看mysql.user的信息

mysql> select user,host from user;+-------+-----------+| user  | host      |+-------+-----------+| admin | %         || root  | 127.0.0.1 || root  | ::1       || root  | localhost |+-------+-----------+4 rows in set (0.04 sec)

创建新用户及授权,已操作成功,本机登录测试OK:

mysql -u admin -pEnter password:

如果远程还连不上:

查看Mysql网络连接,确保本地端口在监听 :

root@ubuntu:~# netstat -an |grep 3306tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN

确保本地防火墙未打开 :

root@ubuntu:~# ufw statusFirewall not loaded

查看/etc/mysql/my.cnf找到bind-address=127.0.0.1,直接改为
bind-address=192.168.0.xxx(本机ip)

之后重启mysql就OK了。






Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn