mysql默认安装目录说明

本文详细介绍了MySQL安装完成后的重要目录,包括数据库目录、配置文件、相关命令和启动脚本,并提供了如何修改登录密码、启动与停止MySQL的方法。此外,还指导了如何更改MySQL目录以及配置文件的调整。

转自http://blog.sina.com.cn/s/blog_48a770da0100oond.html

MySQL安装完成后不象SQL<wbr>Server默认安装在一个目录,它的数据库文件、配置文件和命令文件分别在不同的目录,了解这些目录非常重要,尤其对于Linux的初学者,因为<wbr>Linux本身的目录结构就比较复杂,如果搞不清楚MySQL的安装目录那就无从谈起深入学习。</wbr></wbr>

<wbr><wbr>下面就介绍一下这几个目录。<br style="line-height:22px"><wbr><wbr>1、数据库目录<br style="line-height:22px"><wbr><wbr>/var/lib/mysql/<br style="line-height:22px"><wbr><wbr>2、配置文件<br style="line-height:22px"><wbr><wbr>/usr/share/mysql(mysql.server命令及配置文件)<br style="line-height:22px"><wbr><wbr>3、相关命令<br style="line-height:22px"><wbr><wbr>/usr/bin(mysqladmin<wbr>mysqldump等命令)<br style="line-height:22px"><wbr><wbr>4、启动脚本<br style="line-height:22px"><wbr><wbr>/etc/rc.d/init.d/(启动脚本文件mysql的目录)<br style="line-height:22px"><wbr><wbr>修改登录密码<br style="line-height:22px"><wbr><wbr>MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。<br style="line-height:22px"><wbr><wbr>1、命令<br style="line-height:22px"><wbr><wbr>usr/bin/mysqladmin<wbr>-u<wbr>root<wbr>password<wbr>'new-password'<br style="line-height:22px"><wbr><wbr>格式:mysqladmin<wbr>-u用户名<wbr>-p旧密码<wbr>password<wbr>新密码<br style="line-height:22px"><wbr><wbr>2、例子<br style="line-height:22px"><wbr><wbr>例1:给root加个密码123456。<br style="line-height:22px"><wbr><wbr>键入以下命令<wbr>:<br style="line-height:22px"><wbr><wbr>[root@test1<wbr>local]#<wbr>/usr/bin/mysqladmin<wbr>-u<wbr>root<wbr>password<wbr>123456<br style="line-height:22px"><wbr><wbr>注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。<br style="line-height:22px"><wbr><wbr>3、测试是否修改成功<br style="line-height:22px"><wbr><wbr>1)不用密码登录<br style="line-height:22px"><wbr><wbr>[root@test1<wbr>local]#<wbr>mysql<br style="line-height:22px"><wbr><wbr><wbr><br style="line-height:22px"> ERROR<wbr>1045:<wbr>Access<wbr>denied<wbr>for<wbr>user:<wbr>[email='root@localhost']'root@localhost'[/email]<wbr>(Using<wbr>password:<wbr>NO)<br style="line-height:22px"><wbr><wbr>显示错误,说明密码已经修改。<br style="line-height:22px"><wbr><wbr>2)用修改后的密码登录<br style="line-height:22px"><wbr><wbr>[root@test1<wbr>local]#<wbr>mysql<wbr>-u<wbr>root<wbr>-p<br style="line-height:22px"><wbr><wbr>Enter<wbr>password:<wbr>(输入修改后的密码123456)<br style="line-height:22px"><wbr><wbr>Welcome<wbr>to<wbr>the<wbr>MySQL<wbr>monitor.<wbr>Commands<wbr>end<wbr>with<wbr>;<wbr>or<wbr>g.<br style="line-height:22px"><wbr><wbr>Your<wbr>MySQL<wbr>connection<wbr>id<wbr>is<wbr>4<wbr>to<wbr>server<wbr>version:<wbr>4.0.16-standard<br style="line-height:22px"><wbr><wbr>Type<wbr>'help;'<wbr>or<wbr>'h'<wbr>for<wbr>help.<wbr>Type<wbr>'c'<wbr>to<wbr>clear<wbr>the<wbr>buffer.<br style="line-height:22px"><wbr><wbr>mysql&gt;<br style="line-height:22px"><wbr><wbr>成功!<br style="line-height:22px"><wbr><wbr>这是通过mysqladmin命令修改口令,也可通过修改库来更改口令。<br style="line-height:22px"><wbr><wbr>启动与停止<br style="line-height:22px"><wbr><wbr>1、启动<br style="line-height:22px"><wbr><wbr>MySQL安装完成后启动文件mysql在/etc/init.d目录下,在需要启动时运行下面命令即可。<br style="line-height:22px"><wbr><wbr>[root@test1<wbr>init.d]#<wbr>/etc/init.d/mysql<wbr>start<br style="line-height:22px"><wbr><wbr>2、停止<br style="line-height:22px"><wbr><wbr>/usr/bin/mysqladmin<wbr>-u<wbr>root<wbr>-p<wbr>shutdown<br style="line-height:22px"><wbr><wbr>3、自动启动<br style="line-height:22px"><wbr><wbr>1)察看mysql是否在自动启动列表中<br style="line-height:22px"><wbr><wbr>[root@test1<wbr>local]#<wbr>/sbin/chkconfig<wbr>–list<br style="line-height:22px"><wbr><wbr>2)把MySQL添加到你系统的启动服务组里面去<br style="line-height:22px"><wbr><wbr>[root@test1<wbr>local]#<wbr>/sbin/chkconfig<wbr>–-<wbr>add<wbr>mysql<br style="line-height:22px"><wbr><wbr>3)把MySQL从启动服务组里面删除。<br style="line-height:22px"><wbr><wbr>[root@test1<wbr>local]#<wbr>/sbin/chkconfig<wbr>–-<wbr>del<wbr>mysql<br style="line-height:22px"> 更改MySQL目录<br style="line-height:22px"><wbr><wbr>MySQL默认的数据文件存储目录为/var/lib/mysql。假如要把目录移到/home/data下需要进行下面几步:<br style="line-height:22px"><wbr><wbr>1、home目录下建立data目录<br style="line-height:22px"><wbr><wbr>cd<wbr>/home<br style="line-height:22px"><wbr><wbr>mkdir<wbr>data<br style="line-height:22px"><wbr><wbr>2、把MySQL服务进程停掉:<br style="line-height:22px"><wbr><wbr>mysqladmin<wbr>-u<wbr>root<wbr>-p<wbr>shutdown<br style="line-height:22px"><wbr><wbr>3、把/var/lib/mysql整个目录移到/home/data<br style="line-height:22px"><wbr><wbr>mv<wbr>/var/lib/mysql<wbr>/home/data/<br style="line-height:22px"><wbr><wbr>这样就把MySQL的数据文件移动到了/home/data/mysql下<br style="line-height:22px"><wbr><wbr>4、找到my.cnf配置文件<br style="line-height:22px"><wbr><wbr>如果/etc/目录下没有my.cnf配置文件,请到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个到/etc/并改名为my.cnf)中。命令如下:<br style="line-height:22px"><wbr><wbr>[root@test1<wbr>mysql]#<wbr>cp<wbr>/usr/share/mysql/my-medium.cnf<wbr>/etc/my.cnf<br style="line-height:22px"><wbr><wbr>5、编辑MySQL的配置文件/etc/my.cnf<br style="line-height:22px"><wbr><wbr>为保证MySQL能够正常工作,需要指明mysql.sock文件的产生位置。<wbr>修改socket=/var/lib/mysql/mysql.sock一行中等号右边的值<br style="line-height:22px"><wbr><wbr>为:/home/mysql/mysql.sock<wbr>。操作如下:<br style="line-height:22px"><wbr><wbr>vi<wbr><wbr>my.cnf<wbr><wbr><wbr><wbr>(用vi工具编辑my.cnf文件,找到下列数据修改之)<br style="line-height:22px"><wbr><wbr>#<wbr>The<wbr>MySQL<wbr>server<br style="line-height:22px"><wbr><wbr>[mysqld]<br style="line-height:22px"><wbr><wbr>port<wbr><wbr><wbr>=<wbr>3306<br style="line-height:22px"><wbr><wbr>#socket<wbr><wbr>=<wbr>/var/lib/mysql/mysql.sock(原内容,为了更稳妥用“#”注释此行)<br style="line-height:22px"><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<think>好的,我需要回答用户关于MySQL 8.0默认安装目录的问题。首先,用户提供的引用中有四个来源,但看起来都是关于修改数据目录的,特别是引用[1]到[4]都提到了修改MySQL8.0的数据目录路径。不过用户的问题是关于默认安装目录的位置,这可能与操作系统有关。 根据我的知识,MySQL在不同操作系统下的默认安装路径不同。比如,在Windows上,通常安装路径可能类似于C:\Program Files\MySQL\MySQL Server 8.0,而数据目录默认可能在安装目录下的data文件夹。而在Linux系统如CentOS,默认安装目录可能是在/usr/local/mysql或者/var/lib/mysql。但需要确认用户的操作系统。 不过查看用户提供的引用,引用[1]中的路径是D:\MySQL-8.0\mysql-8.0.23-winx64\bin,这可能是用户自定义的安装路径,但用户想知道的是默认位置。引用[3]和[4]提到的是Linux下的配置,可能默认在/var/lib/mysql,但需要结合不同系统的情况。 因此,我应该分系统说明:Windows和Linux的默认安装目录。同时,引用中的内容主要涉及数据目录的修改,可能安装目录和数据目录不同。需要明确回答用户的问题,即默认安装目录的位置,而不是数据目录。但用户可能有时候会混淆这两个概念,所以可能需要解释两者的区别。 然后,引用中提到的操作,例如在Windows下通过命令行初始化,路径可能不是默认的,但用户可能自己指定了安装路径。所以需要指出默认路径,并结合引用中的例子说明用户可能在安装时自定义了路径,但默认路径通常是标准位置。 总结回答结构: 1. 分操作系统说明默认安装目录。 2. 区分安装目录和数据目录。 3. 提供如何查找当前安装目录的方法,例如通过命令行或配置文件。 4. 引用中的例子可能帮助说明,比如引用[1]中的路径是自定义的,而默认可能在Program Files下。</think>MySQL 8.0 的默认安装目录和配置路径会根据操作系统的不同有所区别,以下是详细说明: --- ### **一、默认安装目录** #### **1. Windows系统** - **安装目录**:默认路径为 `C:\Program Files\MySQL\MySQL Server 8.0\` 如果安装时未自定义路径,通常会在此位置找到 `bin`(可执行文件)、`data`(默认数据目录)等子文件夹[^1]。 - **数据目录**:默认位于安装目录下的 `data` 文件夹,即 `C:\Program Files\MySQL\MySQL Server 8.0\data`[^4]。 #### **2. Linux系统(如CentOS/Ubuntu)** - **安装目录**:默认通过包管理器安装时,文件可能分布在以下路径: - `/usr/bin/`(客户端工具) - `/usr/sbin/`(服务端程序) - `/var/lib/mysql/`(默认数据目录)[^3] - **手动编译安装**:可能位于 `/usr/local/mysql/`。 --- ### **二、如何验证当前安装目录** #### **通过MySQL命令行查询** 1. 登录MySQL后执行: ```sql SHOW VARIABLES LIKE 'basedir'; -- 显示安装目录 SHOW VARIABLES LIKE 'datadir'; -- 显示数据目录 ``` 结果示例(Windows): ``` basedir | C:\Program Files\MySQL\MySQL Server 8.0\ datadir | C:\Program Files\MySQL\MySQL Server 8.0\data\ ``` #### **通过配置文件查找** - **Windows**:查看 `my.ini`(通常位于 `C:\ProgramData\MySQL\MySQL Server 8.0\`)中的 `basedir` 和 `datadir` 参数[^2]。 - **Linux**:查看 `/etc/my.cnf` 或 `/etc/mysql/my.cnf`[^3]。 --- ### **三、安装目录 vs 数据目录** - **安装目录**:存储MySQL服务程序、客户端工具等。 - **数据目录**:存储数据库文件(如表、日志等),默认安装目录绑定,但可通过配置迁移(如用户引用中修改 `datadir` 的示例)[^4]。 --- ### **四、用户引用中的自定义示例** 用户提供的引用[^1]中路径 `D:\MySQL-8.0\mysql-8.0.23-winx64\bin` 是自定义安装路径,而非默认位置。此类操作需通过修改 `my.ini` 或启动参数实现[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值