MySQL的密码设置
由MySQL使用用户名和口令的方法与Unix或Windows使用的方式有很多不同之处: ·MySQL使用于认证目的的用户名,与Unix用户名(登录名字)或Windows用户名无关。缺省地,大多数MySQL客户尝试使用当前Unix用户名作为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; Copy after login |
重新设置一个遗忘的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; Copy after login |
(如果存在一个能从任意地址登录的root用户,初始化授权表后,生成该用户,为了安全,你可能已经删除该用户)。
其实也可以直接修改授权表:
mysql> use mysql; mysql> update user set password =password('yourpass') where user='root'; Copy after login |
你可能使用工具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。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA
