Mysqli 简明教程
MySQLi - Installation
Downloading MySQL
MySQLi 扩展旨在与 MySQL 4.1.13 版或更高版本配合使用,因此必须下载 MySQL。所有 MySQL 下载内容均位于 MySQL Downloads 。选择您需要的 MySQL Community Server 的最新版本号,并尽可能准确地选择您需要的平台。
The MySQLi extension is designed to work with MySQL version 4.1.13 or newer, So have to download MySQL. All downloads for MySQL are located at MySQL Downloads. Pick the latest version number for MySQL Community Server you want and, as exactly as possible, the platform you want.
Installing MySQL on Linux/UNIX
在 Linux 系统上安装 MySQL 的推荐方式是通过 RPM。MySQL AB 使以下 RPM 可在其网站上下载 −
The recommended way to install MySQL on a Linux system is via RPM. MySQL AB makes the following RPMs available for download on its web site −
-
MySQL − The MySQL database server, which manages databases and tables, controls user access, and processes SQL queries.
-
MySQL-client − MySQL client programs, which make it possible to connect to and interact with the server.
-
MySQL-devel − Libraries and header files that come in handy when compiling other programs that use MySQL.
-
MySQL-shared − Shared libraries for the MySQL client.
-
MySQL-bench − Benchmark and performance testing tools for the MySQL database server.
此处列出的 MySQL RPM 都是在 SuSE Linux 系统上构建的,但通常可在其他 Linux 版本上轻松工作。
The MySQL RPMs listed here are all built on a SuSE Linux system, but they’ll usually work on other Linux variants with no difficulty.
现在,按以下步骤继续安装 −
Now, follow the following steps to proceed for installation −
-
Login to the system using root user.
-
Switch to the directory containing the RPMs −
-
Install the MySQL database server by executing the following command. Remember to replace the filename in italics with the file name of your RPM.
[root@host]# rpm -i MySQL-5.0.9-0.i386.rpm
-
This is optional but recommended step to install the remaining RPMs in the same manner −
[root@host]# rpm -i MySQL-client-5.0.9-0.i386.rpm
[root@host]# rpm -i MySQL-devel-5.0.9-0.i386.rpm
[root@host]# rpm -i MySQL-shared-5.0.9-0.i386.rpm
[root@host]# rpm -i MySQL-bench-5.0.9-0.i386.rpm
Installing MySQL on Windows
现在,在任何版本的 Windows 上进行默认安装比以前容易得多,因为 MySQL 现在已与安装程序很好地打包在一起。只需下载安装程序包,将其解压缩到任何位置,然后运行 setup.exe。
Default installation on any version of Windows is now much easier than it used to be, as MySQL now comes neatly packaged with an installer. Simply download the installer package, unzip it anywhere, and run setup.exe.
默认安装程序 setup.exe 将引导您完成琐碎的进程,并且默认情况下将把所有内容安装在 C:\mysql 下。
Default installer setup.exe will walk you through the trivial process and by default will install everything under C:\mysql.
通过从命令提示符中首次启动服务器来测试服务器。转到可能是 C:\mysql\bin 的 mysqld 服务器位置,然后键入 −
Test the server by firing it up from the command prompt the first time. Go to the location of the mysqld server which is probably C:\mysql\bin, and type −
mysqld.exe --console
NOTE − 如果在 NT 上,则必须使用 mysqld-nt.exe 而不是 mysqld.exe
NOTE − If you are on NT, then you will have to use mysqld-nt.exe instead of mysqld.exe
如果一切顺利,您会看到一些有关启动和 InnoDB 的消息。如果不是,您可能有权限问题。确保储存数据的目录对数据库进程运行所在的任何用户(可能是 mysql)都是可访问的。
If all went well, you will see some messages about startup and InnoDB. If not, you may have a permissions issue. Make sure that the directory that holds your data is accessible to whatever user (probably mysql) the database processes run under.
MySQL 不会将自身添加到开始菜单中,并且也没有特别好的 GUI 方式来停止服务器。因此,如果你倾向于通过双击 mysqld 可执行文件来启动服务器,你应记住通过使用 mysqladmin、任务列表、任务管理器或其他 Windows 特定方式手动停止进程。
MySQL will not add itself to the start menu, and there is no particularly nice GUI way to stop the server either. Therefore, if you tend to start the server by double clicking the mysqld executable, you should remember to halt the process by hand by using mysqladmin, Task List, Task Manager, or other Windows-specific means.
Verifying MySQL Installation
在成功安装 MySQL、初始化基本表以及启动服务器后,您可以通过一些简单的测试来验证一切是否应正常工作。
After MySQL has been successfully installed, the base tables have been initialized, and the server has been started, you can verify that all is working as it should via some simple tests.
Use the mysqladmin Utility to Obtain Server Status
使用 mysqladmin 二进制文件检查服务器版本。此二进制文件在 Linux 上的 /usr/bin 中和 Windows 上的 C:\mysql\bin 中可用。
Use mysqladmin binary to check server version. This binary would be available in /usr/bin on linux and in C:\mysql\bin on windows.
[root@host]# mysqladmin --version
它将在 Linux 上生成以下结果。它可能随你的安装而变化 −
It will produce the following result on Linux. It may vary depending on your installation −
mysqladmin Ver 8.23 Distrib 5.0.9-0, for redhat-linux-gnu on i386
如果您没有收到这样的消息,那么您的安装可能存在一些问题,您需要一些帮助来解决它。
If you do not get such message, then there may be some problem in your installation and you would need some help to fix it.
Execute simple SQL commands using MySQL Client
您可以使用 MySQL 客户端通过使用 mysql 命令连接到 MySQL 服务器。此刻,您无需提供任何密码,因为默认情况下将设置为空白。
You can connect to your MySQL server by using MySQL client using mysql command. At this moment, you do not need to give any password as by default it will be set to blank.
因此,只需使用以下命令
So just use following command
[root@host]# mysql
它应该会得到一个 mysql> 提示符。现在,您已连接到 MySQL 服务器,并且可以按以下方式在 mysql> 提示符处执行所有 SQL 命令 −
It should be rewarded with a mysql> prompt. Now, you are connected to the MySQL server and you can execute all the SQL command at mysql> prompt as follows −
mysql> SHOW DATABASES;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.13 sec)
Post-installation Steps
MySQL 将一个空白的密码用于根 MySQL 用户。一旦你成功安装了数据库和客户端,你就需要按如下方式设置根密码 −
MySQL ships with a blank password for the root MySQL user. As soon as you have successfully installed the database and client, you need to set a root password as follows −
[root@host]# mysqladmin -u root password "new_password";
现在要连接到你的 MySQL 服务器,你必须使用以下命令 −
Now to make a connection to your MySQL server, you would have to use the following command −
[root@host]# mysql -u root -p
Enter password:*******
UNIX 用户还希望将你的 MySQL 目录放在你的 PATH 中,这样你就不必在每次想要使用命令行客户端时输入全部路径。对于 bash,它将是类似下列的内容 −
UNIX users will also want to put your MySQL directory in your PATH, so you won’t have to keep typing out the full path every time you want to use the command-line client. For bash, it would be something like −
export PATH = $PATH:/usr/bin:/usr/sbin
Running MySQL at boot time
如果你想在启动时运行 MySQL 服务器,那么确保你有在 /etc/rc.local 文件中的条目。
If you want to run MySQL server at boot time, then make sure you have following entry in /etc/rc.local file.
/etc/init.d/mysqld start
此外,你应该在 /etc/init.d/ 目录中有 mysqld 二进制文件。
Also,you should have mysqld binary in /etc/init.d/ directory.