In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the basic commands of mysql to create a database, which involves things, learned from the theoretical knowledge, there are many books, literature for your reference, from the perspective of practical significance, accumulated years of practical experience can be shared with you.
First, create a database:
Create database database_name
Cut into the database:
Use database_name
There are two ways to create a database in php:
(mysql_create_db (), mysql_query ())
$conn = mysql_connect ("localhost", "username", "password") or
Die ("could not connect to localhost")
1.
Mysql_create_db ("database_name") or
Die ("could not create database")
two。
$string = "create database database_name"
Mysql_query ($string) or
Die (mysql_error ())
II. Selected database
Before you can create a table, you must select the database where the table you want to create is located
Selected database:
Through the command line client: use database_name
Through php: mysql_select_db ()
$conn = mysql_connect ("localhost", "username", "password") or
Die ("could not connect to localhost")
Mysql_select_db ("test", $conn) or
Die ("could not select database")
Third, build a table
Create table table_name
Such as:
Create table table_name
(
Column_1 column_type column attributes
Column_2 column_type column attributes
Column_3 column_type column attributes
Primary key (column_name)
Index index_name (column_name)
)
You need to type the entire command on the command line client
Used in php, the mysql_query () function
Such as:
$conn = mysql_connect ("localhost", "username", "password") or
Die ("could not connect to localhost")
Mysql_select_db ("test", $conn) or
Die ("could not select database")
$query = "create table my_table (col_1 int not null primary key)
Col_2 text
) "
Mysql_query ($query) or
Die (mysql_error ())
Delete tables and databases
Drop table table_name
Drop database database_name
You can use the drop table command through the mysql_query () function in php
Deleting a database in php requires the use of the mysql_drop_db () function
List all available tables in the database (show tables)
Note: the database must be selected before using this life.
In php, you can use mysql_list_tables () to get the list in the table
6. View the properties and types of columns
Show columns from table_name
Show fields from table_name
Similar information can be obtained using mysql_field_name (), mysql_field_type (), and mysql_field_len ()!
7. View parameter information
View global parameters: show global variables like'% keyword%'
View local parameters: show variables like'% keyword%'
8. View database bin-log log information
[root@localhost] [db1] > show master logs
+-+ | Log_name | File_size | +-+-+ | mysql-bin.000001 | 3530 | +-+-+ 1 row in set ( 0.00 sec) [root@localhost] [db1] > flush logs Query OK, 0 rows affected (0.05sec) [root@localhost] [db1] > show master logs +-+-+ | Log_name | File_size | +-+-+ | mysql-bin.000001 | 3577 | | mysql-bin.000002 | 234 | +- -+ 2 rows in set (0.00 sec) [root@localhost] [db1] > PURGE BINARY LOGS TO 'mysql-bin.000002' Query OK, 0 rows affected (0.01sec) [root@localhost] [db1] > show master logs +-+-+ | Log_name | File_size | +-+-+ | mysql-bin.000002 | 234 | +-+-+
1 row in set (0.00 sec)
Read the above introduction of mysql to create a database of the basic commands, I hope to give you some help in practical application. Due to the limited space in this article, there will inevitably be deficiencies and areas that need to be supplemented. You can continue to pay attention to the industry information section and will update your industry news and knowledge regularly. If you need more professional answers, you can contact us on the official website for 24-hour pre-sales and after-sales to help you answer questions at any time.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Linux package Management RPM = # ldd View dynamic link libraries called by binary programs
© 2024 shulou.com SLNews company. All rights reserved.