The content of this article or any related information is under the Creative Commons license BY, you can republish this content freely but you must mention the author of this article: Kernel and indicate the URL of this page: https://www.exabyteinformatica.com/tienda/foro/an-introduction-to-mysql-t1369.html
At some point to your existence as a Linux administrator, you’re going to need to work with a database. And because you’re working with the Linux platform, likelihood is high that database could be MySQL. In some cases, you’ll most effective deserve to engage with MySQL long satisfactory to create an empty database to be used for a web-based tool, akin to OrangeHRM, Wordpress, Drupal, or Nextcloud. You may also be heading in the right direction to gain knowledge of the open supply database tool, in hopes of one day serving as a database administrator for a company.
Inspired of why, you need to stand up to speed with MySQL...and that very smartly may imply starting from the very beginning. That’s precisely what we’re here for: to deploy MySQL and learn the way to make use of it, while not having to depend upon a GUI device for the entire heavy lifting.
I’ll be demonstrating on a fresh installation of Ubuntu 16.10. Let’s kick this off through installation MySQL.
There are a number of easy methods to install MySQL. You can install it as a standalone server from the command line, which you could installation it from the GUI package manager (as in Ubuntu software), or you can install it alongside a full-blown LAMP (Linux Apache MySQL personal home page) server. Because, greater often than now not, you’ll be using MySQL on a LAMP server, let’s go that route. Why? Because it tends to be the most fulfilling formulation of installation MySQL on a Debian-based mostly distribution.
The installing of a LAMP server will vary from distribution to distribution. For Ubuntu, that intention will also be accomplished with a single command:
sudo apt-get deploy lamp-server^
The above command will installation all the essential dependencies on your LAMP server.
All the way through the installing, you’ll be triggered to enter (and verify) a password for the MySQL “root” consumer (determine 1).
Don't go away this blank. Enter a robust password for the MySQL root person and tab all the way down to adequate, hit Enter in your keyboard, after which retype the new password. The setting up will proceed to completion. You at the moment are ready to start working with MySQL.
Logging into MySQL
To work with MySQL, you have to log into what's referred to as the MySQL Shell. this is fairly different out of your normal bash shell, and you are restricted to MySQL-most effective commands. Should you log into MySQL use the foundation user and the password you simply created (during installing).
When logging in, that you would be able to specify not handiest which person to work with but additionally which database to use. We haven’t created a database yet, so we will only be specifying a consumer. To log in, open up a terminal window, and situation the command:
mysql -u root -p
The -u choice shows what consumer you will log in with and the -p option tells MySQL to require a password. When precipitated, enter the password you created throughout setting up and you will be greeted with the MySQL Shell (determine 2).
Developing a new database
The first element to do is create a new database. Let’s say we need to create a new database known as purchasers. To do that, you’d challenge the command:
CREATE DATABASE valued clientele;
Be aware the ending “;” character. This is essential, because it instructs MySQL of the command conclusion. You may situation that command as:
CREATE DATABASE consumers
And MySQL would return a > immediate. If there were extra to that command, you may enter it there. When you’d completed the command, class; and hit the Enter key to your keyboard. I prefer to enter my commands unexpectedly (to evade confusion).
If you challenge the comprehensive command, MySQL will return:
1 row affected (0.00 sec)
Your database has been created. as it stands, you can't work with that database, because you’re no longer the use of it. to use the newly created shoppers database, you need to difficulty the command:
MySQL will return:
Database modified mysql>
That you could now work with the newly created database.
Creating a desk
Unless you are with ease growing the database to be used by means of a 3rd-birthday party software (and the installation of noted third-birthday celebration application will populate the database with the necessary tips), your database needs records. For a database, information starts with tables. Let’s say we are looking to create a table for our new client database a good way to include right here assistance:
To try this, you first need to know what type of characters may be essential for every entry. The three basic kinds obtainable are:
All three features of suggestions for our desk (identify, e mail, cell phone) might be VARCHAR. Why?
• no longer all names and emails could be the identical size
• For clarity, phone numbers are damaged into 123-456-7890 and the “-” character is not an integer.
Let’s create a table for the purchaser’s database, called hardware. To accomplish that, enter the command (from the MySQL Shell):
CREATE desk hardware (identify VARCHAR(20), e mail VARCHAR(20), phone VARCHAR(20));
The table can be created (figure 3), and you will be again to the MySQL instant.
Now that you've a database and a table, all that is still is to add statistics to the newly created desk.
Adding records to tables
We’re going to add our first entry to the hardware table (which may well be a listing of purchasers that sell or purchase hardware). The entry should be:
Identify: Bethany Nitshimi electronic mail: email@example.com phone: 555-123-4567
Here’s what the MySQL command will seem like:
INSERT INTO hardware (identify,email,mobile) VALUES ("Bethany Nitshimi","firstname.lastname@example.org",”555-123-4567”);
The records can be brought to the desk and MySQL will return you again to the immediate.
if you don’t wish to manually enter the information one row at a time, which you could all the time import it from a text file. The textual content file in question would need to be formatted in a similar fashion as was in the above command. So, to import records into the hardware table, each and every entry of the textual content file would need to be (one per line):
Identify e mail mobile
Bronson Coulter email@example.com 555-987-6543
Be aware: The statistics need to be delineated by using a tab.
After getting that file created (we’ll call it facts), go back to the MySQL Shell (make certain to use the consumer’s database), and concern the command:
LOAD records native INFILE '/course/statistics' INTO table hardware;
The place path is the exact course to the records file.
Which you can view the contents of the hardware table with the command:
opt for * FROM hardware;
MySQL will issue a document on the entire statistics contained with that desk (determine 5).
Your database is in a position
When you’ve added all of the tables and statistics to your database, which you can difficulty the command exit to depart the MySQL Shell. Your database is ready to be used. Youngsters this can best function an introduction to MySQL, make sure you now have a high-quality understanding of a way to deploy MySQL, log in, create a database, create a table, and fill the table with records. If you happen to be able to circulation onto extra advanced subject matters that you could all the time try the reliable MySQL documentation.
No te pierdas el tema anterior: MySQL: Gestión de bases de datos (Curso completo)
Salta al siguiente tema: MySQL 8.0: Records dictionary architecture and design
Quizás también te interese: