Genral syntax
mysql -u DBUSER -h DBSERVERNAME -p
So at a shell prompt you type all one single line to connect to database server install on localhost for root user:
mysql -u root -h localhost -p
Supply the password when prompted for password.
2. Use PHP to connect to MySQL
http://www.cyberciti.biz/faq/how-to-connect-to-my-mysql-database-server-using-command-line-and-php/
$link = mysql_connect("localhost", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE");
$query = "SELECT * FROM TABLE";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result))
{
foreach ($line as $value)
{
print "$value\n";
}
}
mysql_close($link);
3. Mysql list databases
http://www.cyberciti.biz/faq/mysql-command-to-show-list-of-databases-on-server/
mysql> show databases;
output
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
Use database
mysql> use test;
List tables
mysql> show tables;
4. Create a mysql database
http://www.cyberciti.biz/faq/howto-linux-unix-creating-database-and-table/
Create database
mysql>CREATE DATABASE books;
Use database
USE books;
Create Table
mysql>CREATE TABLE authors (id INT, name VARCHAR(20), email VARCHAR(20));
Add data
mysql>INSERT INTO authors (id,name,email) VALUES(1,"Vivek","xuz@abc.com");
Display all rows
mysql>SELECT * FROM authors;
5. Drop database / table
Drop database
mysql>DROP DATABASE atomstore;
No comments:
Post a Comment