How to change Mysql root password under linux ?

本文详细介绍了如何在Linux、FreeBSD、OpenBSD及类UNIX操作系统环境下,通过SSH/Telnet会话更改MySQL根密码的方法。包括使用mysqladmin命令设置初始密码、更改现有密码以及通过MySQL SQL命令直接更新密码的步骤。

How do I change MySQL root password under Linux, FreeBSD, OpenBSD and UNIX like operating system over ssh / telnet session?


mysqladmin command to change root password
Setting up MySQL password is one of the essential tasks. By default root user is MySQL admin account user. Please note that the Linux / UNIX root account for your operating system and MySQL root are different. They are separate and nothing to do with each other. Sometime your may remove mysql root account and setup admin as mysql super user for security purpose.

If you have never set a root password for MySQL server, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:
$ mysqladmin -u root password NEWPASSWORD
However, if you want to change (or update) a root password, then you need to use the following command:
$ mysqladmin -u root -p'oldpassword' password newpass
For example, If the old password is abc, you can set the new password to 123456, enter:

$ mysqladmin -u root -p'abc' password '123456'

Change MySQL password for other users

To change a normal user password you need to type (let us assume you would like to change password for user vivek) the following command:
$ mysqladmin -u vivek -p oldpassword password newpass

Changing MySQL root user password using MySQL sql command

This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user vivek:

1) Login to mysql server, type the following command at shell prompt:
$ mysql -u root -p

2) Use mysql database (type command at mysql> prompt):

mysql> use mysql;

3) Change password for user vivek, enter:

mysql> update user set password=PASSWORD("NEWPASSWORD") where User='vivek';

4) Finally, reload the privileges:

mysql> flush privileges;
mysql> quit

The last method can be used with PHP, Python or Perl scripting mysql API.

Updated for accuracy!
<think>我们正在处理用户的问题:“How to install a .tgz package on Linux” 根据引用内容,特别是引用[4]中详细描述了安装步骤,我们可以总结如下: 1. 解压.tgz文件:使用tar命令解压,因为.tgz等同于.tar.gz 2. 进入解压后的目录 3. 通常需要编译和安装:执行配置(如果有configure脚本)、编译(make)、安装(make install) 但是,需要注意的是,引用[1]提到:大多数Linux tarball包含的是软件的源代码,对于新手建议使用包管理器(如apt-get, rpm, yum)安装二进制包。 因此,在回答中,我们应首先建议用户检查是否有可用的二进制包,如果没有再考虑从源代码安装。 步骤总结: 步骤1:解压文件 步骤2:查看安装说明(如README或INSTALL文件) 步骤3:执行配置、编译和安装(典型的步骤是:./configure && make && make install) 另外,引用[4]提供了详细的命令示例。 根据用户的问题,我们生成以下回答:</think>在Linux系统中安装`.tgz`文件(即`.tar.gz`的压缩格式)通常需要解压、编译和安装源代码。以下是详细步骤: ### 📦 安装步骤 1. **解压文件** 打开终端,进入`.tgz`文件所在目录,执行: ```bash tar -xvzf 文件名.tgz ``` 参数说明: `-x`:解压 `-v`:显示解压过程 `-z`:处理gzip压缩 `-f`:指定文件名 2. **进入解压目录** ```bash cd 解压后的目录名 ``` 3. **查找安装说明** 检查目录中的`README`或`INSTALL`文件,获取具体安装要求: ```bash ls -l cat README # 查看说明 ``` 4. **编译源代码**(典型流程) ```bash ./configure # 配置编译环境(可能需要root权限) make # 编译源代码 sudo make install # 安装到系统目录 ``` ⚠️ 注意: - 若缺少依赖库,需先安装依赖(如`sudo apt install build-essential`) - `./configure`可添加参数(如`--prefix=/opt`指定安装路径) 5. **清理临时文件**(可选) ```bash make clean ``` ### 💡 重要提示 - **优先使用包管理器** 对于新手,建议优先通过`apt`/`yum`等工具安装二进制包(更安全便捷)[^1]。 - **权限问题** 安装系统级软件时需`sudo`权限,用户级软件可安装到`~/local`目录。 - **环境变量** 自定义安装路径后,需将路径加入`PATH`: ```bash echo 'export PATH=/opt/软件名/bin:$PATH' >> ~/.bashrc source ~/.bashrc ``` ### ❓ 相关问题 1. 如何解决`./configure`报错"missing dependencies"? 2. 从源代码安装软件有哪些安全风险? 3. 如何彻底卸载通过`make install`安装的软件? 4. Linux中`.tgz`与`.deb`/`.rpm`包有何本质区别? [^1]: 大多数Linux tarball包含源代码,建议新手优先使用包管理器安装二进制包。 [^4]: 解压后需进入目录,按说明编译安装软件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值