方法1: 用SET PASSWORD命令php
mysql -u roothtml
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');mysql
方法2:用mysqladminweb
mysqladmin -u root password "newpass"sql
若是root已經設置過密碼,採用以下方法數據庫
mysqladmin -u root password oldpass "newpass"編程
方法3: 用UPDATE直接編輯user表服務器
mysql -u root編程語言
mysql> use mysql;ide
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
在丟失root密碼的時候,能夠這樣
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
mysql> FLUSH PRIVILEGES;
字段名 | 數字類型 | 數據寬度 | 是否爲空 | 是否主鍵 | 自動增長 | 默認值 |
id | int | 4 | 否 | primary key | auto_increment | |
name | char | 20 | 否 | |||
sex | int | 4 | 否 | 0 | ||
degree | double | 16 | 是 |
FirstName | LastName | Age |
---|---|---|
Peter | Griffin | 35 |
Glenn | Quagmire | 33 |
<?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); mysql_query("DELETE FROM Persons WHERE LastName='Griffin'"); mysql_close($con); ?>在此次刪除以後,表是這樣的:
FirstName | LastName | Age |
---|---|---|
Glenn | Quagmire | 33 |