apt 安装mysql源码目录_ubuntu 安装mysql及目录位置

本文详细介绍了在Ubuntu上安装、配置、重置MySQL服务器root密码的步骤,包括使用apt-get安装,查看安装端口,编辑my.cnf配置文件,以及如何通过命令行重置root密码。此外,还提到了文件位置、权限分配和防火墙设置,确保MySQL服务的正常运行和远程访问。
摘要由CSDN通过智能技术生成

安装

sudo apt-get install mysql-server mysql-client

查看安装端口情况

sudo netstat -tap | grep mysql

配置文件位置

sudo vim /etc/mysql/my.cnf

打开关闭服务

/etc/init.d/mysql start/stop

卸载

sudo apt-get autoremove --purge mysql-server-5.5.43

sudo apt-get remove mysql-server

sudo apt-get autoremovemysql-server

sudo apt-get remove mysql-common

dpkg -l | grep ^rc| awk '{print $2}' | sudoxargsdpkg -P

其它文件默认位置

[plain] view plaincopy/usr/bin                 客户端程序和脚本  /usr/sbin                mysqld 服务器  /var/lib/mysql           日志文件,数据库  [重点要知道这个]  /usr/share/doc/packages  文档  /usr/include/mysql       包含( 头) 文件  /usr/lib/mysql           库  /usr/share/mysql         错误消息和字符集文件  /usr/share/sql-bench     基准程序

在ubuntu中重置mysql服务器root密码的方法

在ubuntu下安装了mysql 5 server,结果不知道什么原因,安装时输入的root帐号密码在使用时无论如何都不能通过数据库服务器的验证。无奈只有重置mysql的root帐号密码。查了一下,用了以下方法成功的重置了root帐号密码首先停止mysql服务:

root@webserver :/home/webmaster# service mysql stop

接着采用忽略密码认证模式重新创建一个mysql服务:

root@webserver :/home/webmaster# mysqld --user=mysql --skip-grant-tables --skip-networking &

成功启动后返回PID及其它启动信息

[1] 3591

root@webserver :/home/webmaster# 121005 2:59:27 [Note] Plugin 'FEDERATED' is disabled.

121005 2:59:27 InnoDB: The InnoDB memory heap is disabled

121005 2:59:27 InnoDB: Mutexes and rw_locks use GCC atomic builtins

121005 2:59:27 InnoDB: Compressed tables use zlib 1.2.3.4

121005 2:59:27 InnoDB: Initializing buffer pool, size = 128.0M

121005 2:59:27 InnoDB: Completed initialization of buffer pool

121005 2:59:27 InnoDB: highest supported file format is Barracuda.

121005 2:59:27 InnoDB: Waiting for the background threads to start

121005 2:59:28 InnoDB: 1.1.8 started; log sequence number 1595685

121005 2:59:28 [Note] mysqld: ready for connections.

Version: '5.5.24-0ubuntu0.12.04.1' socket: '/var/run/mysqld/mysqld.sock' port: 0 (Ubuntu)

连接到mysql系统库:

root@webserver :/home/webmaster# mysql -u root mysql

连接到mysql库后直接修改root帐号的密码为新的密码'mynewpasswd':

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> update user set Password=PASSWORD('mynewpasswd') where user='root';

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3 Changed: 3 Warnings: 0

mysql> FLUSH PRIVILEGES;

mysql> quit;

Bye

中止mysql服务进程(PID 3591见前面启动服务时的屏幕信息):

root@webserver :/home/webmaster# kill 3591

正常启动 mysql服务,并用新密码登录mysql服务器成功:

root@webserver:/home/webmaster#service mysql start

root@webserver:/home/webmaster#mysql -u root -pmynewpasswd

第四步    配置my.cnf:

使用 sudo netstat -lntp 命令看看

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN

如果上面0 0.0.0.0后面不是3306的话就打开/etc/mysql/my.cnf   吧下面这一行给注释掉

bind-address = 127.0.0.1

修改配置以后记得要重启mysql

第五步   分配权限:

本机登陆mysql:mysql -u root -p (-p一定要有);改变数据库:use mysql;

从所有主机:grant all privileges on *.* to root@"%" identified by "password" with grant option;

从指定主机:grant all privileges on *.* to root@"192.168.11.205" identified by "password" with grant option;

例如:

grant all privileges on *.* to test@'192.168.113.124' identified by '123456'

然后执行

flush privileges;

查看一下user:

select host,user,password from user;

看看刚刚添加的用户是否存在

第六步  使用Navicat 连接:

填好服务器IP,刚刚添加的用户名跟密码,连接吧。有时候可能由于防火墙的原因无法连接,把防火墙给关闭试试。

查看防火墙状态:sudo ufw status

关闭防火墙:sudo ufw disable

开启防火墙:sudo ufw enable

开放端口:sudo ufw allow 3306   (可以只开3306端口,mysql默认使用的3306端口)

关闭端口:sudo ufw delete allow 3306

允许特定IP:sudo ufw allow from 192.168.113.254

删除特定IP:sudo ufw delete allow from 192.168.113.254

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值