1.到 http://www.mysql.com/ 下载 mysql 的安装程序 Setup.exe
-----------------------------------------
2.双击Setup.exe,全部用缺省,完成安装。安装目录:C:\mysql
-----------------------------------------
3.使用WinMySQLadmin.exe这个程序启动或者停止mysql服务,最初启动的时候会要求登录管理员名和密码。
-----------------------------------------
4.MySql第一次启动时会在C:\WINDOWS下自动生成my.ini文件,如果不是用缺省选项安装的话,需要修改这个文件的配置。
-----------------------------------------
5.设置特权用户root的密码
-----------------------------------------
C:\> C:\mysql\bin\mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6 to server version: 4.0.17-nt
mysql> set password for root=password('设置的密码');
mysql> flush privileges;
mysql> exit
Bye
C:\> exit
-----------------------------------------
6.删除匿名用户
C:\> C:\mysql\bin\mysql -u root -p
Enter password: 设置的密码
mysql> use mysql;
mysql> delete from user where password='';
mysql> flush privileges;
mysql> exit
Bye
C:\> exit
-----------------------------------------
7.创建用户数据库
C:\> C:\mysql\bin\mysql -u root -p
Enter password: 设置的密码
mysql> create database user_db;
mysql> exit
Bye
C:\> exit
-----------------------------------------
8.确认创建的数据库
C:\> C:\mysql\bin\mysql -u root -p
Enter password: 设定的密码
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
| user_db |
+----------+
3 rows in set (0.00 sec)
mysql> exit
Bye
C:\> exit
-----------------------------------------
9.创建一般用户
用户名 db_user 密码 123456
C:\> C:\mysql\bin\mysql -u root -p
Enter password: 设置的密码
mysql> grant select,insert,delete,update,create,drop,file,
alter,index on *.* to db_user identified by '123456';
mysql> flush privileges;
mysql> exit
Bye
C:\> exit
-----------------------------------------
10.用一般用户创建表
C:\> C:\mysql\bin\mysql -u db_user -p
Enter password: 123456
mysql>
mysql> use user_db;
Database changed
mysql>
mysql> create table cars(
-> id text not null,
-> model text,
-> year text
-> );
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> show fields from cars;
+-------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-----+---------+-------+
| id | text | NO | | NULL | |
| model | text | YES | | NULL | |
| year | text | YES | | NULL | |
+-------+------+------+-----+---------+-------+
3 rows in set (0.13 sec)
mysql>
mysql> exit
Bye
C:\> exit
如果没有设置MySql开机自动启动,运行下边的命令手动启动MySql
net start mysql
-----------------------------------------
11.PHP中连接MySql
首先修改php.ini文件,让PHP加载Mysql模块。
①「;extension=php_mysql.dll」将这句的注释放开。
②extension_dir设置为php目录下php_mysql.dll文件所在的路径。
例:extension_dir = "D:/php-5.2.11-Win32/ext/"
③重启Apache.
下面的网页访问刚才建立的car表并显示所有表内数据。
<htm>
<head>
<title> PHP Connect to MySql Test </title>
</head>
<body>
<?php
$username = "db_user";
$password = "123456";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("user_db",$dbhandle)
or die("Could not select user_db");
//execute the SQL query and return records
$result = mysql_query("SELECT id, model,year FROM cars");
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
echo "ID:".$row{'id'}." Name:".$row{'model'}."Year: ". //display the results
$row{'year'}."<br>";
}
//close the connection
mysql_close($dbhandle);
?>
</body>
</html>
-----------------------------------------
12.为了方便管理MySql,可到 http://www.phpmyadmin.net/home_page/downloads.php 下载 phpMysqlAdmin来管理MySql.只需将下载后的压缩文件解压后放到Apache的htdocs目录下即可。
■如果出现:无法加载 mcrypt 扩展,请检查您的 PHP 配置。把php.ini里面的;extension=php_mcrypt.dll 注释放开就可以了。
■如果出现:没有找到 PHP 扩展 mbstring,而您现在好像在使用多字节字符集。把php.ini里面;extension=php_mbstring.dll放开注释
■如果出现: 配置文件现在需要一个短语密码。 则在config.inc.php里找到blowfish_secret,随便设置一个密码即可以了。