In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article is to share with you about how to create a database in MySQL. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Let's create a database with MySQL. Here are the specific steps:
Create a database with MySQL to confirm that the MySQL server process is running. If not, start it manually:
# / etc/rc.d/init.d/mysql start
Now that we start it as the administrator of the MySQL client, we will see a prompt for a password:
# mysql-u root-p
Enter password: newpassword
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 13 to server version: 3.22.21
Type''help'' for help.
Mysql >
Create a new database
Create a new database called example with the command: create database example. When using MySQL clients, remember to add; (semicolon) at the end of each command
Mysql > create database example
Query OK, 1 row affected (0.03 sec)
Mysql > use example
Database changed
Create a new table
Create a table called mytable in the database named example:
Mysql > CREATE TABLE mytable (
> name CHAR (30)
-> phone CHAR (10)
->)
Query OK, 0 rows affected (0.00 sec)
Tip: many Linux systems use bash's Shell, which can display the history of commands you have used, just by using the up and down keys, so you can save a lot of time to enter complex commands.
Add data
Now let's enter some data into the database. For example, to insert some entries into the table, here are the steps:
Mysql > INSERT INTO mytable VALUES ("Homer Simpson", "555-1234")
Query OK, 1 row affected (0.05sec)
Mysql > INSERT INTO mytable VALUES ("Bart Simpson", "555-4321")
Query OK, 1 row affected (0.00 sec)
Mysql > INSERT INTO mytable VALUES ("Lisa Simpson", "555-3214")
Query OK, 1 row affected (0.00 sec)
Mysql > INSERT INTO mytable VALUES ("Marge Simpson", "555-2314")
Query OK, 1 row affected (0.00 sec)
Mysql > INSERT INTO mytable VALUES ("Maggie Simpson", "555-3142")
Query OK, 1 row affected (0.00 sec)
Verify that all the information can be seen through the SELECT instruction:
Mysql > SELECT * FROM mytable
+-+ +
| | name | phone |
+-+ +
| | Homer Simpson | 555-1234 | |
| | Bart Simpson | 555-4321 | |
| | Lisa Simpson | 555-3214 | |
| | Marge Simpson | 555-2314 | |
| | Maggie Simpson | 555-3142 | |
+-+ +
5 rows in set (0.00 sec)
Create a new database user
We have set up a database and entered some data. You must now create a new user account so that you can access the database, and grant this user privileges with the GRANT command:
Mysql > GRANT usage
-> ON example.*
-> TO webuserlocalhost
Query OK, 0 rows affected (0.15 sec)
After that, a new user is created called webuser, which can only connect to the database from localhost and can connect to the example database. Next, we must specify what the user webuser can do:
Mysql > GRANT select, insert, delete
-> ON example.*
-> TO webuserlocalhost
Query OK, 0 rows affected (0.00 sec)
This action enables webuser to perform query operations such as SELECT,INSERT and DELETE on tables in each example database. Now let's finish the operation and exit the MySQL client:
Mysql > exit
Bye
The above is how to create a database in MySQL. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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
© 2024 shulou.com SLNews company. All rights reserved.