MySQL 密码设置_MySQL
bitsCN.com
一个重要的应用就是如何在遗忘root用户密码的时候修改密码,使用的方法是启动MySQL服务器时忽略加载授权表。
由MySQL使用用户名和口令的方法与Unix或Windows使用的方式有很多不同之处:
MySQL 使用于认证目的的用户名,与Unix用户名(登录名字)或Windows用户名无关。缺省地,大多数MySQL客户尝试使用当前 Unix用户名作为MySQL用户名登录,但是这仅仅为了方便。客户程序允许用-u或--user选项指定一个不同的名字,这意味着无论如何你不能使得一个数据库更安全,除非所有的MySQL用户名都有口令。任何人可以试图用任何名字连接服务器,而且如果他们指定了没有口令的任何名字,他们将成功。
MySQL用户名最长可以是16各字符;典型地,Unix用户名限制为8个字符。
MySQL口令与Unix口令没关系。在你使用登录到一台Unix机器口令和你使用在那台机器上存取一个数据库的口令之间没有必要有关联。
MySQL加密口令使用了一个Unix登录期间所用的不同算法。
本节将介绍如何为MySQL数据库系统的用户修改密码。
使用myadmin实用程序
使用mysqladmin实用程序修改密码的命令行是:
shell>mysqladmin -u user -p password "newpassword"
运行这个命令,在提示输入密码时,数据就密码,则用户user的密码就被改为newpassword
。如果,原来的用户没有密码,则不比指定-p选项。例如,初始化授权表之后,root用户的密码就是空的,你可以这样为root用户设立密码:
shell>mysqladmin -u root password "newpassword"
使用语句SET PASSWORD
使用mysqladmin为用户修改密码有一个明显的缺点,就是必须知道用户原来的密码,如果是为了给遗忘了密码的用户重设密码就无能为力了。一个专门用于修改密码的SQL语句为SET PASSWORD:
SET PASSWORD = PASSWORD('some password')
设置当前用户的口令。任何非匿名的用户能改变他自己的口令!
连接到服务器后,你可以这样改变自己的密码:
mysql> SET PASSWORD = PASSWORD('another pass');
SET PASSWORD FOR user = PASSWORD('some password')
设置当前服务器主机上的一个特定用户的口令。只有具备存取mysql数据库的用户可以这样做。用户应该以user@hostname格式给出,这里 user和hostname完全与他们列在mysql.user表条目的User和Host列一样。例如,如果你有一个条目其User和Host字段是 'bob'和'%.loc.gov',你将写成:
mysql> SET PASSWORD FOR bob@"%.loc.gov" = PASSWORD("newpass");
直接修改授权表
另一种修改,密码的方法是直接修改授权表user。只有具备存取mysql数据库的用户可以这样做。
例如,如果你有一个条目其User和Host字段是'bob'和'%.loc.gov',你将写成:
mysql> UPDATE mysql.user SET password=PASSWORD("newpass") where user="bob' AND host="%.loc.gov";
mysql>FLUSH PRIVILEGES;
重新设置一个遗忘的root口令
如果你遗忘了root用户的口令,那么将会是一件非常麻烦的事。除非你有其它有特权的用户,否则很多操作都无法完成,例如,关闭数据库等等。
你应当选用--without-grant-tables选项启动mysqld服务,你可以在这时更改授权表的相关内容,也可以用mysqlaccess检查你的授权是否到位。
例如,如果你忘记了你的MYSQL的root口令的话,你可以通过下面的过程恢复。
1、关闭MySQL服务器
向mysqld server 发送kill命令关掉mysqld server(不是 kill -9),存放进程ID的文件通常在MYSQL的数据库所在的目录中。
kill `cat /mysql-data-directory/hostname.pid`
你必须是UNIX的root用户或者是你所运行的SERVER上的同等用户,才能执行这个操作。
如果在windows平台上,也可以停止进程。如果是NT还可以用net stop mysql命令关闭数据库。
2、使用'--skip-grant-tables' 参数来启动 mysqld。
Unix平台:
$su mysql
$safe_mysqld --skip-grant-tables &
Windows平台:
C:/mysql/bin>mysqld --skip-grant-tables
以上语句,假定都位于正确的目录。
3、连接到服务器,修改口令
使用'mysql -h hostname mysql'命令登录到mysqld server ,用grant命令改变口令:
mysql>GRANT ALL ON *.* TO root@localhost INDENTIFIED BY 'new password'
-> WITH GRANT OPTION;
mysql>GRANT ALL ON *.* TO root@% INDENTIFIED BY 'new password'
-> WITH GRANT OPTION;
(如果存在一个能从任意地址登录的root用户,初始化授权表后,生成该用户,为了安全,你可能已经删除该用户)。
其实也可以直接修改授权表:
mysql> use mysql;
mysql> update user set password =password('yourpass') where user='root';
你可能使用工具mysqladmin修改密码:
shell> mysqladmin -h hostname -u root password 'new password
但是它修改的密码语服务器匹配的用户有关。如果,你从服务器主机连接,那么服务器匹配的是root@localhost,修改该用户密码,否则一般修改root@%密码,除非你有其它root用户存在。
4. 载入权限表:
shell> mysqladmin -h hostname flush-privileges
或者使用 SQL 命令`FLUSH PRIVILEGES'。
当然,在这里,你也可以重启mysqld。bitsCN.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Solving the problem of slow Photoshop startup requires a multi-pronged approach, including: upgrading hardware (memory, solid-state drive, CPU); uninstalling outdated or incompatible plug-ins; cleaning up system garbage and excessive background programs regularly; closing irrelevant programs with caution; avoiding opening a large number of files during startup.

How to implement Windows-like in front-end development...

Pull vertical guides in Photoshop: Enable ruler view (View > ruler). Hover the mouse over the vertical edge of the ruler, and then the cursor becomes a vertical line with double arrows and hold and drag the mouse to pull out the reference line. Click Delete by dragging the guide, or hovering it into a cross.

The solution to MySQL installation error is: 1. Carefully check the system environment to ensure that the MySQL dependency library requirements are met. Different operating systems and version requirements are different; 2. Carefully read the error message and take corresponding measures according to prompts (such as missing library files or insufficient permissions), such as installing dependencies or using sudo commands; 3. If necessary, try to install the source code and carefully check the compilation log, but this requires a certain amount of Linux knowledge and experience. The key to ultimately solving the problem is to carefully check the system environment and error information, and refer to the official documents.

Unable to access MySQL from the terminal may be due to: MySQL service not running; connection command error; insufficient permissions; firewall blocks connection; MySQL configuration file error.

The MySQL connection may be due to the following reasons: MySQL service is not started, the firewall intercepts the connection, the port number is incorrect, the user name or password is incorrect, the listening address in my.cnf is improperly configured, etc. The troubleshooting steps include: 1. Check whether the MySQL service is running; 2. Adjust the firewall settings to allow MySQL to listen to port 3306; 3. Confirm that the port number is consistent with the actual port number; 4. Check whether the user name and password are correct; 5. Make sure the bind-address settings in my.cnf are correct.

The main reasons for MySQL installation failure are: 1. Permission issues, you need to run as an administrator or use the sudo command; 2. Dependencies are missing, and you need to install relevant development packages; 3. Port conflicts, you need to close the program that occupies port 3306 or modify the configuration file; 4. The installation package is corrupt, you need to download and verify the integrity; 5. The environment variable is incorrectly configured, and the environment variables must be correctly configured according to the operating system. Solve these problems and carefully check each step to successfully install MySQL.
