Beruflich Dokumente
Kultur Dokumente
Community Menu
About MySQL
MySQL is an open source database management software that helps users store, organize, and retrieve data. It is a very powerful program
with a lot of flexibilitythis tutorial will provide the simplest introduction to MySQL
Ubuntu:
Centos:
mysql -u root -p
After entering the root MySQL password into the prompt (not to be confused with the root droplet password), you will be able to start building
your MySQL database.
Sign up for our newsletter. Get the latest tutorials on SysAdmin and open source topics.
Two points to keep in mind: S C R O L L TO TO P
Enter your email address Sign Up
https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial 1/8
06/06/2017 A Basic MySQL Tutorial | DigitalOcean
All MySQL commands end with a semicolon; if the phrase does not end with a semicolon, the command will not execute.
Also, although it is not required, MySQL commands are usually written in uppercase and databases, tables, usernames, or text are in
lowercase to make them easier to distinguish. However, the MySQL command line is not case sensitive.
SHOW DATABASES;
In MySQL, the phrase most often used to delete objects is Drop. You would delete a MySQL database with this command:
The first step is to create a new table within the larger database.
USE events;
In the same way that you could check the available databases, you can also see an overview of the tables that the database contains.
SHOW tables;
Sign up for our newsletter. Get the latest tutorials on SysAdmin and open source topics.
S C R O L L TO TO P
Enter
Sinceyour
thisemail
is a new
address
database, MySQL has nothing to show, and you
Sign Upwill get a message that says, Empty set
https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial 2/8
06/06/2017 A Basic MySQL Tutorial | DigitalOcean
CREATE TABLE potluck (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(20),
food VARCHAR(30),
confirmed CHAR(1),
signup_date DATE);
Lets take a look at how the table appears within the database using the "SHOW TABLES;" command:
We can remind ourselves about the tables organization with this command:
DESCRIBE potluck;
Keep in mind throughout that, although the MySQL command line does not pay attention to cases, the table and database names are case
sensitive: potluck is not the same as POTLUCK or Potluck.
mysql>DESCRIBE potluck;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | YES | | NULL | |
| food | varchar(30) | YES | | NULL | |
| confirmed | char(1) | YES | | NULL | |
| signup_date | date | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
Once you input that in, you will see the words:
Sign up for our newsletter. Get the latest tutorials on SysAdmin and open source topics.
S C R O L L TO TO P
EnterQuery OK, 1
your email row affected (0.00 sec)
address Sign Up
https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial 3/8
06/06/2017 A Basic MySQL Tutorial | DigitalOcean
Lets add a couple more people to our group:
INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL, "Sandy", "Key Lime Tarts","N", '2012-04-14');
INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL, "Tom", "BBQ","Y", '2012-04-18');
INSERT INTO `potluck` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL, "Tina", "Salad","Y", '2012-04-10');
UPDATE `potluck`
SET
`confirmed` = 'Y'
WHERE `potluck`.`name` ='Sandy';
You can also use this command to add information into specific cells, even if they are empty.
This command puts the new column called "email" at the end of the table by default, and the VARCHAR command limits it to 40 characters.
However, if you need to place that column in a specific spot in the table, we can add one more phrase to the command.
Now the new email column goes after the column name.
Just as you can add a column, you can delete one as well:
https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial 4/8
06/06/2017 A Basic MySQL Tutorial | DigitalOcean
Notice that the id numbers associated with each person remain the same.
By Etel Sverdlov
DigitalOcean Monitoring
Collect metrics, monitor Droplet
performance, and receive alerts when
problems arise in your infrastructure
no configuration required. Coming 2017.
READ MORE
Related Tutorials
Understanding SQL And NoSQL Databases And Different Database Models
How To Migrate a MySQL Database Between Two Servers
How To Set Up Master Slave Replication in MySQL
How To Import and Export Databases and Reset a Root Password in MySQL
How To Create a New User and Grant Permissions in MySQL
46 Comments
Leave a comment...
Log In to Comment
Signerikchacon
up for our newsletter.
February 18, 2013 Get the latest tutorials on SysAdmin and open source topics.
S C R O L L TO TO P
Enter
0 your email address Sign Up
https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial 5/8
06/06/2017 A Basic MySQL Tutorial | DigitalOcean
Very good quick tutorial to mysql !!
Thanks
0 I kept getting errors when trying to create my first table. It finally worked when I excluded these quotation marks `potluck`
(`id`,`name`,`food`,`confirmed`,`signup_date`). Only the VALUES need quotation marks. Not sure if that is just my version of mySQL. I followed the
tutorials on here to install it
1 If you're trying to allow remote connections to the MySQL server, then open /etc/mysql/my.conf and comment out the line "bind-address
127.0.0.1". This will cause MySQL to bind to any address, allowing for remote connections. Then you can use iptables in combination with
CREATE USER username@'some-ip-address-or-%-wildcard' to control access to the server.
1 @ruz.irani Table/column names should be escaped with backticks (`), while values and strings should be escape with single-quotation marks (').
0 It is really useful. Some more if you explain about mysql would be more helpful. Thanks a lot
S.Sivarama Sarma
0 How do I import a database from phpmyadmin from another server, If I have the sql file, how do I upload that?
0 404 error
0 @nguyentien.jobs: The password you entered is incorrect -- are you sure it's the correct password?
0 Do, What is the default password set for Mysql server when we create the droplet with one click application, LAMP on UBUNTU
Sign up for our newsletter. Get the latest tutorials on SysAdmin and open source topics.
S C R O L L TO TO P
bda.awk
Enter October
your email 8, 2013
address Sign Up
0
https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial 6/8
06/06/2017 A Basic MySQL Tutorial | DigitalOcean
0 Hello
How do I create mysql accounts for each domain in my drop?
Thanks!
MySQL is a powerful database management system used for organizing and retrieving data. This tutorial explains how to to create new MySQL
users and how to grant them the appropriate permissions.
0 Hi, I'm having a problem on mysqld. after I reboot my laptop, I got this issue.
"ERROR 2002 (HY000): can't connect to local mysql server through socket /var/lib/mysql/mysql.socket (1111)"
I already tried to search the issue on google but it didn't gave the answer. I hope someone could help. Thanks a lot in advance!
0 @richardcarl.mendoza: That means MySQL isn't running -- did you configure it to start on boot?
0 Thank you!
1 GOOD MORNING;
VERY GOOD MY FRIEND I LIKE IT.
THANKS FOR TUTORIAL.
Sign up create
0 how for ourtable
newsletter.
and insert
Get values
the latestinto thaton
tutorials using c programming
SysAdmin in mysql
and open source
topics. on linux OS.
S C R O L L TO TO P
please give solution in as simple as possible.
Enter your email address Sign Up
https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial 7/8
06/06/2017 A Basic MySQL Tutorial | DigitalOcean
Copyright 2017 DigitalOcean Inc.
Distros & One-Click Apps Terms, Privacy, & Copyright Security Report a Bug Get Paid to Write Shop
Sign up for our newsletter. Get the latest tutorials on SysAdmin and open source topics.
S C R O L L TO TO P
Enter your email address Sign Up
https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial 8/8