[root@dyw219 ~]# ssh root@kvm8.deyu.wang root@kvm8.deyu.wang's password: Last login: Sat Dec 6 09:45:29 2014 from 192.168.122.1 [root@kvm8 ~]#
[root@kvm8 ~]# mysqladmin -uroot -p create dyw Enter password:
mysql_query
產生資料庫 dywphp。
[root@kvm8 ~]# cd /var/www/html/ [root@kvm8 html]# vim createdb.php [root@kvm8 html]# cat createdb.php <html> <head> <title>Creating MySQL Database</title> </head> <body> <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = '123qwe'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully<br />'; $sql = 'CREATE DATABASE dywphp'; $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not create database: ' . mysql_error()); } echo "Database dywphp created successfully\n"; mysql_close($conn); ?> </body> </html>
[root@kvm8 html]# php createdb.php <html> <head> <title>Creating MySQL Database</title> </head> <body> Connected successfully<br />Database dywphp created successfully </body> </html>
[root@kvm8 html]# mysql -uroot -p123qwe -e "show databases" +--------------------+ | Database | +--------------------+ | information_schema | | dyw | | dywphp | | mysql | | performance_schema | | test | +--------------------+