[root@kvm8 html]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 21 Server version: 5.5.38 MySQL Community Server (GPL) by Remi Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use dyw; Database changed mysql> show tables; Empty set (0.00 sec) mysql> exit Bye
mysql_select 選取資料庫 dywphp。
[root@kvm8 ~]# cd /var/www/html
[root@kvm8 html]# vim selectdb.php
[root@kvm8 html]# cat selectdb.php
<html>
<head>
<title>Selecting MySQL Database</title>
</head>
<body>
<?php
$dbhost = 'localhost:3306';
$dbuser = 'dywang';
$dbpass = '123qwe';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db( 'dywphp' );
mysql_close($conn);
?>
</body>
</html>
[root@kvm8 html]# php selectdb.php <html> <head> <title>Selecting MySQL Database</title> </head> <body> Connected successfully</body> </html>