Everything you need to know about mysql. MySQL is an open source package. Connecting to MySQL server

Teachers and mentors who teach MySQL can offer their own options for organizing the sequence of learning MySQL in the comments to this section textbook. Also, readers who lead can offer their comments on the organization of the textbook. self-study MySQL. In order for self-study of MySQL to be effective, it is necessary to involve the methodological experience that MySQL training provides. A primer should help quick start developer.

Databases: basic concepts

Document table of contents

In life, we often encounter the need to store some information, and therefore we often deal with databases.

For example, we use notebook to store your friends' phone numbers and plan your time. A phone book contains information about people living in the same city. These are all some kind of databases. Well, since these are databases, let’s see how data is stored in them. For example, the phone book is a table (Table 10.1).

In this table, the data is the actual phone numbers, addresses and full names, i.e. the lines “Ivanov Ivan Ivanovich”, “32-43-12”, etc., and the names of the columns of this table, i.e. the lines “Full name”, “Phone number” and “Address” specify the meaning of this data, their semantics.

Table 10.1. Database Example: Phone Book

Now imagine that there are not two, but two thousand entries in this table, you are creating this directory and somewhere an error occurred (for example, a typo in the address). Apparently, it will be difficult to find and fix this error manually. You need to use some kind of automation. For driving big amount data programmers (with the help of mathematicians) came up with database management systems (DBMS). Compared to text databases, electronic DBMSs have a huge number of advantages, including the ability quick search information, the relationship of data with each other before using this data in various application programs ah and simultaneous access to data by several users.

For accuracy, we will give the definition of a database proposed by Glossary.ru

A database is a collection of related data organized according to certain rules that provide general principles description, storage and manipulation, independent of application programs. The database is information model subject area. Databases are accessed using a database management system (DBMS). The DBMS provides support for creating databases, centralized management and organizing access to them for various users.

So, we came to the conclusion that it is advisable to store data independently of programs, so that they are interconnected and organized according to certain rules. But the question of how to store data and by what rules it should be organized remained open. There are many ways (by the way, they are called data representation or data storage models). The most popular are object and relational data models.

By relational model E. Codd is considered to be the first to propose using the apparatus of set theory (union, intersection, difference, Cartesian product) for data processing and showed that any representation of data is reduced to a set of two-dimensional tables of a special type, known in mathematics as a relation.

Thus, a relational database is a set of tables (exactly the same as the one above) related to each other. A row in the table corresponds to an entity real world(in the example above, this is information about the person).

Examples relational DBMS: Mysql, PostgreSql. The basis object model based on the concept of object-oriented programming, in which data is represented as a set of objects and classes interconnected by related relationships, and work with objects is carried out using hidden (encapsulated) objects
methods.

Examples object DBMS: Cache, GemStone (from Servio Corporation), ONTOS (ONTOS).

IN Lately DBMS manufacturers strive to combine these two approaches and advocate an object-relational model for data representation. Examples of such DBMS are IBM DB2 for Common Servers, Oracle8.

Since we are going to work with Mysql, we will discuss aspects of working only with relational databases data. There are two more important concepts left for us to consider in this area: keys and indexing, after which we can start learning the language SQL queries.

1. Keys

First, let's think about this question: what information needs to be given about a person so that the interlocutor can definitely say that this is the right person, there can be no doubt, there is no other like him? Giving a last name is obviously not enough, since there are namesakes. If the interlocutor is a person, then we can approximately explain who we are talking about, for example, remember the action that that person committed, or something else. The computer will not understand such an explanation; it needs clear rules on how to determine who we're talking about. In database management systems, the concept of a primary key was introduced to solve this problem.

Primary key (PK) – minimum set fields that uniquely identify a record in a table. This means that a primary key is, first of all, a set of table fields, secondly, each set of values ​​of these fields must define a single record (row) in the table and, thirdly, this set of fields must be the minimum of all those with the same property.

Since a primary key defines only one unique record, no two table records can have the same identical values primary key.

For example, in our table (see above), full name and address allow us to uniquely highlight a record about a person. Speaking in general, without connection with the problem being solved, then such knowledge does not allow us to accurately indicate a single person, since there are namesakes living in different cities at the same address. It's all about the boundaries we set for ourselves. If we believe that knowing the full name, phone number and address without specifying the city is enough for our purposes, then everything is fine, then the full name and address fields can form a primary key. In any case, the problem of creating a primary key falls on the shoulders of the one who designs the database (develops the data storage structure). The solution to this problem can be either the selection of characteristics that naturally define a record in the table (setting the so-called logical, or natural, PK), or the creation of an additional field intended specifically for uniquely identifying records in the table (setting the so-called surrogate, or artificial, PK).

An example of a logical primary key is a passport number in a database of residents' passport data or full name and address in phone book(table above). To set a surrogate primary key, we can add an id (identifier) ​​field to our table, the value of which will be an integer unique for each row of the table. Using such surrogate keys makes sense if the natural primary key is big set fields or its selection is non-trivial.

In addition to uniquely identifying a record, primary keys are used to organize relationships with other tables.

For example, we have three tables: one containing information about historical figures (Persons), one containing information about their inventions (Artifacts), and one containing images of both persons and artifacts (Images) (Figure 10.1).

The primary key in all these tables is the id field. The Artifacts table has an author field, which records the identifier assigned to the author of the invention in the Persons table. Each value in this field is a foreign key to the primary key of the Persons table. Additionally, the Persons and Artifacts tables have a photo field that references an image in the Images table. These fields are also foreign keys to the primary key of the Images table and establish a one-to-one logical relationship between Persons-Images and Artifacts-Images. That is, if the value of the external key photo in the personality table is 10, then this means that the photograph of this person has id=10 in the image table. Thus, foreign keys are used to organize relationships between database tables (parent and child) and to maintain referential integrity constraints.

2. Indexing

One of the main tasks that arise when working with databases is the search task. At the same time, since the database, as a rule, contains a lot of information, programmers are faced with the task of not just searching, but effective search, i.e. search in a relatively short time and with sufficient accuracy.

To do this (to optimize query performance), some table fields are indexed. Using indexes is useful for quickly finding rows with a specified value in one column. Without an index, a table is read through the entire table, starting with the first record, until matching rows are found. How more table, the higher the overhead costs. If the table contains an index on the columns in question, the database can quickly locate a search position in the middle of the data file without having to scan through all the data. This happens because the database places indexed fields closer in memory so that their values ​​can be found more quickly. For a table containing 1000 rows, this will be at least 100 times faster compared to iterating through all the records sequentially. However, in the case where almost all 1000 rows need to be accessed, sequential reads will be faster because there are no disk seeks required. So sometimes indexes are just a hindrance. For example, if a large amount of data is copied into a table, then it is better not to have any indexes. However, in some cases it is necessary to use several indexes at once (for example, to process queries on frequently used tables).

If we talk about Mysql, then there are three types of indexes: PRIMARY, UNIQUE, and INDEX, and the word key (KEY) is used as a synonym for the word index (INDEX). All indexes are stored in memory as B-trees.

PRIMARY – a unique index (key) with the restriction that all fields indexed by it cannot have an empty value (i.e. they are NOT NULL). A table can only have one primary index, but it can consist of multiple fields.

UNIQUE – a key (index) that specifies fields that can only have unique values.

INDEX is a regular index (as we described above). In Mysql, you can also index string fields by given number characters from the beginning of the line.

3. Mysql DBMS

Let's continue the conversation about the Mysql DBMS. Mysql is relational system database management. That is, the data in its databases is stored in the form of logically interconnected tables, accessed using the SQL query language. Mysql is a freely distributed system, i.e. you don't need to pay to use it. In addition, it is a fairly fast, reliable and, most importantly, easy to use DBMS, quite suitable for not too global projects.

You can work with Mysql not only in text mode, but also graphically. There is a very popular visual interface (by the way, written in PHP) for working with this DBMS. It's called PhpMyAdmin. This interface makes it much easier to work with databases in Mysql.

PhpMyAdmin allows you to use all the advantages of the browser, including scrolling the image if it does not fit on the screen. Many of the basic SQL functions of working with data in PhpMyAdmin are reduced to intuitive clear interfaces and actions reminiscent of following links on the Internet. But, nevertheless, it is still worth working in text mode.

Before moving on to detailed study SQL language, a few words about Mysql installation and preparation for work. If you do not intend to administer the server, then the information below will only be useful to you. general development. So, installing Mysql is very simple - automatically, click OK a couple of times, and that’s it. After this, you can go to the directory where files like Mysql.exe, Mysqld.exe, etc. are located. (for us under Windows XP this is c:\Mysql\bin) Latest file starts the Mysql server. On some systems, the server runs as a service. After starting the server, you should start the Mysql client by running the Mysql.exe program. They won't even ask for a password here. Moreover, if you type shell> Mysql.exe -u root or shell>Mysql -u root Mysql you will get full Mysql server administrator rights. By the way, you need to execute these commands while in the directory where the Mysql.exe files are located.
To begin with, without going into details of the commands, let’s fix these two shortcomings (the administrator does not have a password and the ability for anonymous users to log in):

All information about Mysql users stores in the user table in a special database Mysql data, which can only be accessed by the server administrator. Therefore, to change any password, you need to change this table. The password is set using the PASSWORD function, which encodes the entered data. In addition to changing the administrator password, you also need to delete all users who do not have a login (DELETE command). The Flush Privileges command forces changes made in system base data (Mysql).

Now let's create a database that we will work with (we are still working as a server administrator):
Mysql>create database book;

As you can see, all commands in Mysql end with a semicolon. If you forgot to put this sign, then you are prompted to put it until it is done:

Mysql>show tables
->
->

Now last action- let's create simple user, give him access to the created database, and start working.

Mysql> GRANT ALL PRIVILEGES ON book.* TO nina@localhost
IDENTIFIED BY "123";

The GRANT command gives the user nina, who logged into the server from the same machine (from localhost) and identified by the password “123”, certain rights (in in this case everyone) to all tables of the book database. Now we can log out and log in as user nina with the appropriate password:

shell>Mysql -u nina -p
Enter password: ***
Welcome to the Mysql monitor!...
Mysql>

If you are going to use the database on someone else's server, then its administrator will do all the steps described above for you, i.e. will configure everything and create the user and database. The next chapter describes SQL language commands that are useful for working with data stored in the Mysql DBMS.

4.

5.

6.

7. Building an interface for adding information

So, we have some kind of table in the database. To build an interface for adding information to this table, you need to display its structure (i.e., a set of its fields) in an HTML form.

Let's break this task down into the following subtasks:

  • establishing a connection to the database;
  • selecting a working database;
  • getting a list of table fields;
  • displaying fields in an html form.
After this, the data entered into the form must be recorded in the database.

Let's consider all these tasks in order.

8. Establishing a connection

So, the first thing to do is to establish a connection to the database.

Let's use the Mysql_connect function.

Mysql_connect syntax

Mysql_connect resource ([string server
[, string username [, string password
[, boolean new_link
[, integer client_flags]]]]])

This function establishes a connection with Mysql server and returns a pointer to this connection or FALSE on failure.

Missing parameters are set to the following default values:
server = "localhost:3306"
username = username of the server process owner
password = empty password

If the function is called twice with the same parameters, then a new connection is not established, but a reference to the old connection is returned.

To avoid this, use the new_link parameter, which forces one more connection to be opened in any case.

The client_flags parameter is a combination of the following constants:

MYSQL_CLIENT_COMPRESS (use compression protocol),
MYSQL_CLIENT_IGNORE_SPACE (allows you to insert spaces after function names), MYSQL_CLIENT_INTERACTIVE (wait interactive_timeout seconds - instead of wait_timeout - until the connection is closed).

The new_link parameter was introduced in PHP 4.2.0, and the client_flags parameter was introduced in PHP 4.3.0.

The connection to the server is closed when the script completes execution, unless it was previously closed using the Mysql_close() function.

So, we establish a connection to the database on local server for user nina with password 123:

$conn = Mysql_connect (

or die( "Unable to install
connection: "
. mysql_error());
echo "Connection established";
Mysql_close($conn);
?>

The Mysql_connect action is equivalent to the command

shell>Mysql -u nina -p123

9. Selecting a database

After establishing the connection, we need to select the database with which we will work. Our data is stored in the book database. In Mysql, database selection is done using the use command:

Mysql>use book;


In PHP there is a Mysql_select_db function for this.

Mysql_select_db syntax:

Boolean

Mysql_select_db(string database_name[, resource link_identifier])

This function returns TRUE if the database selection is successful and FALSE

  • otherwise.
Let's make the book database working:

$conn = Mysql_connect (
"localhost" , "nina" , "123" )
or die( "Unable to install
connection: "
. mysql_error());
echo "Connection established";
Mysql_select_db("book");
?>

10. Getting a list of table fields

Now you can start solving the problem itself. How to get a list of table fields? Very simple. PHP also has its own command for this case - Mysql_list_fields.

10.1. Mysql_list_fields syntax

resource Mysql_list_fields (
string database_name,
string table_name
[, resource link_identifier])

This function returns a list of fields in table table_name in database database_name. It turns out that we didn’t have to select a database, but this will come in handy later. As you can see, the result of this function is a resource type variable. That is, this is not exactly what we wanted to get. This is a link that can be used to obtain information about table fields, including their names, types, and flags.

The Mysql_field_name function returns the name of the field resulting from the query. The Mysql_field_len function returns the length of the field. The Mysql_field_type function returns the field type, and the Mysql_field_flags function returns a space-separated list of field flags. Field types can be int, real, string, blob, etc. Flags can be not_null, primary_key, unique_key, blob,
auto_increment, etc.

The syntax for all these commands is the same:

string Mysql_field_name (result resource, int field_offset)
string Mysql_field_type(result resource, int field_offset)
string Mysql_field_flags(result resource, int field_offset)
string Mysql_field_len(result resource, integer field_offset)

Here result is the identifier of the query result (for example, a query sent by the Mysql_list_fields or Mysql_query functions (more on this later)), and field_offset is the ordinal number of the field in the result.

Generally speaking, what functions like Mysql_list_fields or Mysql_query return is a table, or more precisely, a pointer to it. To get specific values ​​from this table, you need to use special functions that read this table row by row. Such functions include Mysql_field_name, etc. To iterate through all the rows in the query result table, you need to know the number of rows in this table. The command Mysql_num_rows(result resource) returns the number of rows in the result set
result.

Now let’s try to get a list of fields in the Artifacts table (a collection of exhibits).

$conn = Mysql_connect (
"localhost" , "nina" , "123" )
or die( "Unable to install
connection: "
. mysql_error());
echo "Connection established";
Mysql_select_db("book");
$list_f = Mysql_list_fields (
"book" , "Artifacts" , $conn );
$n = Mysql_num_fields($list_f);
for($i = 0 ; $i< $n ; $i ++){



$flags_str = Mysql_field_flags (
$list_f , $i );
echo "
Field name: " . $name_f ;
echo "
Field type: " . $type ;
echo "
Field length: " . $len ;
echo "
Field flag string: "
.
$flags_str . "


" ;
}
?>

The result should be something like this (if the table has only two fields, of course):

Field name: id
Field type: int
Field length: 11
Field flag string:
not_null primary_key auto_increment
Field name: title
Field type: string
Field length: 255
Field flag string:
Displaying a list of fields in an html form

Now let's slightly correct the previous example. We will not just display information about the field, but display it in a suitable html form element. So, elements of the BLOB type will be converted to textarea (note that the description field, which we created with the TEXT type, is displayed as having a BLOB type), numbers and strings will be displayed as text input lines , and the element that has the auto-increment label will not be displayed at all, since its value is set automatically.

All this can be solved quite simply, with the exception of selecting the auto_increment flag from the list of flags. To do this you need to use the explode function.

Explode syntax:

array explode(string separator, string string [, int limit ])

This function splits string into parts using separator and returns an array of the resulting strings.

In our case, we need to take the space " as the separator, and the string of field flags as the source string for splitting.

So, let's create a form for entering data into the Artifacts table:

$conn = Mysql_connect("localhost" , "nina" , "123" );
// establish a connection
$database = "book" ;
$table_name = "Artifacts" ;
Mysql_select_db($database); // select the database for
// work

// number of rows in the result
// previous request (i.e. how many in total
// fields in the Artifacts table)
echo "

" ;
// create a form for data entry
echo "

Add new row in
$table_name
"
;
echo "" ;
// for each field we get its name, type, length and flags
for($i = 0 ; $i< $n ; $i ++){
$type = Mysql_field_type($list_f, $i);
$name_f = Mysql_field_name($list_f, $i);
$len = Mysql_field_len($list_f, $i);
$flags_str = Mysql_field_flags($list_f, $i);
// make an array from a string of flags,
// where each array element is a field flag
$flags = explode (" ", $flags_str);
foreach ($flags as $f )(
if ($f == "auto_increment" ) $key = $name_f ;
// remember the autoincrement name
}
/* for each non-autoincrement field in
depending on its type, display the appropriate form element */
if ($key<>$name_f )(
echo "" ;
switch ($type)(
case "string" :
$w = $len / 5 ;
echo "" ;
break;
case "int" :
$w = $len / 4 ;
echo "" ;
break;
case "blob" :
echo "" ;
break;
}
}
echo "" ;
}
echo "

" . $name_f . "
size = $w >size = $w >
" ;
echo "" ;
echo "" ;
?>

If there are no open connections, the function tries to connect to the DBMS, similar to the Mysql_connect() function without parameters. The query result is buffered.

Note: The query string must NOT end with a semicolon.

For SELECT, SHOW, EXPLAIN, DESCRIBE queries only, Mysql_query() returns a pointer to the result of the query, or FALSE if the query was not executed. Otherwise, Mysql_query() returns TRUE if the query succeeds and FALSE if it fails. A value other than FALSE indicates that the request was completed successfully. It does not indicate the number of rows affected or returned. It is quite possible that a successful query will not affect a single row. Mysql_query() is also considered an error and will return FALSE if the user does not have sufficient rights to work with the table specified in the query.

So now we know how to send a query to insert rows into the database.
$list_f = Mysql_list_fields($database, $table_name);
// get a list of fields in the database
$n = Mysql_num_fields($list_f); // number of rows in the result
// previous request
// create one query for all table fields at once
$sql = "INSERT INTO $table_name SET "; // start creating
// query, iterate through all fields of the table
for($i = 0 ; $i< $n ; $i ++){
$name_f = Mysql_field_name($list_f, $i); // calculate the field name
$value = $_POST [ $name_f ]; // calculate the field value
$j = $i + 1 ;
$sql = $sql . $name_f . " = "$value"" ; // add to
// string $sql pair name=value
if ($j<>$n ) $sql = $sql . ", " ; // if the field is not
// last in the list, then put a comma
}
// before writing something to the database,
// you can see what kind of request was received
//echo $sql;
$result = Mysql_query ($sql, $conn); // send a request
// display a message whether the request was completed successfully
if (! $result ) echo " Can"t add ($table_name) " ;
else echo "Success!
" ;
?>

Listing 11.0.2. insert.php

So, we solved the problem of adding data using the web interface. However, there is one subtlety here. When solving this problem, we did not take into account the fact that the values ​​of some fields (author, photo) must be taken from other tables (Persons, Images). Since Mysql does not work with foreign keys, this point remains on the conscience of the system developers, i.e. on our conscience. It is necessary to add the program in such a way that it is possible to enter the correct values ​​in such fields. But we will not do this, since the purpose of the lecture is to introduce the reader to the elements of technology, and not to create a working system. In addition, the reader’s knowledge is quite sufficient to solve this problem on his own. We will turn to another task - displaying data stored in the Mysql DBMS database.

12.

13.

14.

15. Literature

http://mysql.ru/docs/man/
http://www.intuit.ru/department/database/mysql/

Andrey Klochkov

What is MySQL

Before drawing conclusions about whether the MySQL package is worth using as a database server, you first need to find out what it is. MySQL is a relational DBMS.

MySQL supports SQL (Structured Query Language) and can be used as a SQL server. This means that you can communicate with the server in SQL: the client sends a request to the server, which processes it and gives the client only the data that was received as a result of this request. Thus, the client does not need to download data and perform calculations, as, for example, in Microsoft Access.

In addition, MySQL is open source software, i.e. it can be freely studied and modified. The package is distributed under the terms of the GPL (General Public License) and can be downloaded free of charge from the Internet (http://www.mysql.com) for non-commercial use.

With the advent of Internet technologies that make it possible to create dynamic Web pages, the demand for DBMSs that would be most suitable for this in terms of speed, reliability and stability has increased enormously. And here the MySQL package performed well, which turned out to be fast, simple and reliable, but, however, at the expense of functionality deterioration (let’s immediately make a reservation that the MySQL developers promise to add the missing functions in the next versions of the program).

By and large, the absence of some functions that were sacrificed for speed and reliability does not create much trouble for users (although sometimes some discomfort does occur). MySQL is not up to the task of running a full-fledged corporate database, but MySQL copes quite well with everyday tasks.

Flaws

Here is a short list of the main features that MySQL is missing.

Transactions- allow you to combine several SQL queries into one unit of work and, if any of the queries included in this unit fail, perform a rollback to return the data to its original state. Let's explain with an example.

You need to withdraw money from one account and put it into another. To do this, you need to execute two SQL queries: the first is to withdraw money from one account, the second is to credit it to another account. If you do not apply transactions, then if the second request fails, the money will be withdrawn from the account, but will not be credited to another account. Using transactions allows you to roll back as if the money had not been withdrawn from the account at all.

Note that using the LOCK TABLES command in MySQL you can emulate a transaction. This command locks the table while queries are executed, thereby ensuring data integrity, but still cannot be rolled back.

Triggers- serve to automate control over the state and operation of the database. The trigger is stored in the database and fires when a certain event occurs. Let's take the same example with the transfer of money: if the second request fails, a trigger will fire, which will roll back or send a message to the database administrator.

Stored procedures- these are several SQL commands that are stored in the database under a certain name and together perform a certain function. Using stored procedures, you can extend the syntax of SQL so that it is similar to a conventional programming language (for example, Oracle PL/SQL). In our money transfer example, we could save two SQL queries under the same name, and then call this procedure, passing it two account numbers and the amount of money as parameters.

Then both queries would be executed in one transaction. Nested Queries

- allow you to substitute values ​​into the selection conditions dynamically, based on the results of executing another query. According to the author, if you can somehow manage without all of the above, then the lack of nested queries sometimes really spoils life. For example, to find out which vehicle transported more cargo than the fleet average, you need to make the following SQL query:

SELECT auto FROM autopark WHERE massa > !More than what? I have no idea what the average is!

To do this, the average value in the massa field needs to be calculated:

SELECT AVG(massa) FROM autopark

If nested queries are supported, then these two queries can be nested inside each other:

SELECT auto FROM autopark WHERE massa >(SELECT AVG(massa) FROM autopark)

But in the case of MySQL, the average value has to be found separately and substituted into another query directly in the CGI script, which undoubtedly affects performance. UNION instruction

- simply put, it combines the output of several queries into one, with the ability to eliminate duplicate rows. Cascade data update

- Allows you to delete and update related data. For example, when you delete a customer record from the database, all order records for that customer are automatically deleted from the related tables.

Advantages

Now let's list the advantages of MySQL. Performance.

Thanks to the internal multithreading mechanism, MySQL performance is very high. Safety.

A fairly high level of security is ensured thanks to the mysql database, which is created during installation of the package and contains five tables. Using these tables, you can describe which user from which domain can work with which table and what commands he can use. Passwords stored in the database can be encrypted using MySQL's built-in password() function.

License. Thanks to this, you can add the necessary functions to the package yourself, expanding its functionality as you require. By the way, the MySQL authors themselves can do this for you for a fee. To order the MySQL extension from the creators of the package, simply go to http://www.mysql.com and fill out the appropriate form.

Reliability. The creators of MySQL did a great job: as far as I know, this package is quite stable and difficult to break. I don't specifically track reports of hacker attacks on MySQL, but I have never seen (unlike the same Web servers) a message that MySQL was damaged as a result of someone's malicious intent.

Resources. This may depend on various factors, but in any case you will not need a supercomputer.

Community. As a result of the openness of the code, the free nature of the program, and its stable and reliable operation, a community of people has formed who are not only loyal to MySQL, but also participate in every possible way both in the development of the package itself and in training less experienced people to work with it. There are a huge number of mailing lists and conferences where you can get free help at any time of the day.

Portability. Currently, there are versions of the program for most common computer platforms. This means that you are not being forced to use a specific operating system. You can choose what to work with, for example, Linux or Windows, but even if you change the OS, you will not lose your data and you will not even need additional tools to transfer it.

I don't know whether the fact that MySQL does not have a graphical user interface (GUI) is a disadvantage or an advantage. For example, it is more convenient for me to write a SQL query manually (by the way, the results of its execution can be redirected to a file) than to use the query wizard, as in Microsoft SQL Server.

There are several client programs for MySQL that have a GUI, but they are far from perfect and for the most part only slow down the work. If you prefer GUI, I recommend downloading and trying these programs to encourage their creators to further improve their products. Here is a far from complete list of programs with GUI:

  • Winmysqladmin - included in the MySQL Windows distribution, has a standard graphical interface and allows you to administer MySQL;
  • MySqlManager - included in the Windows distribution of MySQL, it contains client functions (but the author was not able to do anything serious with its help);
  • MySQL Administrator for Windows is a more advanced third-party utility. Allows you to register and connect simultaneously to several MySQL servers, create, delete and change the structure of databases and tables, create keys in tables, write SQL queries and save them in a file:
  • XMySQL is a MySQL client for X Window-like systems. Provides full access to tables, allows bulk inserts and deletions, has a query designer and package administration functions. The program can be found at http://web.wt.net/~dblhack/.

A more complete list of all kinds of utilities for MySQL (and it is very large) is at http://www.mysql.com/downloads/.

There you will find a lot of interesting and useful things: exporting data from MySQL to Microsoft Access and vice versa, ODBC drivers, etc.

  • Despite the lack of a graphical interface, the MySQL package includes quite powerful administration tools with a command line interface. Below is a list of them with brief descriptions of the utilities.
  • MySQLAdmin is the main MySQL administration tool. With it, you can create, destroy, modify databases and have complete control over your server.
  • MySQLDump is a data backup utility.
  • MySQLAccess - allows you to change access rights tables and display their contents in an easy-to-read form.
  • MySQLBug - in the event of a bug in MySQL, this utility creates a bug report for the program developers, also sending it to the MySQL mailing list so that experts can help solve your problem.
  • MySQLImport - Imports data from a delimited file into the database.

MySQLShow - shows the structure of databases and the tables they consist of.

MySQL also has its own SQL language extension. These functions can be used in a query in two ways. First, as a value to be retrieved: the function is included in the list of fields to be retrieved. The function's return value will be calculated for each table record and displayed as if it were a table field. For example, let's display the title of the article and its length:

SELECT title, LENGTH(title) FROM table

As a result, we get two columns, where one is taken from the table, and the second was calculated.

Secondly, the function can be used as part of a WHERE clause - in this case, it will replace a constant at the time the query is executed. Let me explain with an example: you need to find events that happened more than a day ago.

SELECT event FROM table WHERE time>(Unix_TIMESTAMP()-(60*60*24))

Here the Unix_TIMESTAMP() function calculates the current time, from which we subtract one day.

Application

According to the author, the most suitable area of ​​application for MySQL is the Internet, thanks to the good security system of this package, stable operation and high performance. If your Internet project lacks transactions, you can use Postgres. Postgres is in many ways similar to MySQL, almost as good in performance, but has more functionality. However, as experience shows, MySQL’s capabilities are quite sufficient for simple Internet projects.

As for using MySQL as a corporate database, the situation here is not very favorable. Let's formulate the requirements for the SQL server of a corporate database, based on the specifics of the employees' work, and evaluate MySQL from the point of view of these requirements.

Ability to work with multiple users. This obvious requirement should be supplemented by the fact that the intensity of database use in this case will be much higher than on a Web server. In fact, for a website, 20 visitors at the same time is considered a great success, and in the case of a corporate base, even a small company can boast of this indicator. Particular attention should be paid to the fact that a corporate database uses more complex user interfaces than pages on a website; in other words, it sends requests to the server more intensively. In technical terms, this means that locking is needed at the level of the record being modified. Here MySQL does not perform well: it locks at the table level. This means, in particular, that if someone enters an order, then all queries (analyzing statistics, selecting records for a report, etc.) will have to wait until the order has been entered. In the case of a corporate database, this negates even such an advantage of MySQL as speed.

Data integrity control at the SQL server level. A corporate database has a complex data schema, and it is very difficult to maintain data integrity using client software: one relation can connect five to seven tables, and the number of tables can reach 30-40. And in this case, the ability to cascade update and delete records in related tables, which MySQL lacks, becomes significant.

In addition, we already mentioned that the enterprise database uses a more complex interface, and this circumstance gives rise to two more requirements: support for all standard SQL statements (and useful extensions), as well as the use of stored procedures and triggers. Alas, MySQL is not happy here either.

Summarizing all that has been said, we can conclude that for most Internet projects, the capabilities of the MySQL DBMS are quite sufficient. They will also be sufficient to store an address book on the company’s internal network.

» Why use MySQL?

Navigation through the Tutorial: 1.1 What is MySQL? 20 language, log_bin, long_query_time 4.21 lower_case_table_names, max_allowed_packet, max_binlog_cache_size 4.22 max_connections, max_connect_errors, max_delayed_threads 4.23 max_join_size, max_sort_length, max_user_connections 4.24 max_tmp_tables, max_write_lock_count, am_sort_buffer_size 4.25 mуisam_max_extra_sоrt_file_size, myisam_max_sort_file_size, net_buffer_length 4.26 net_read_timeout, net_retry_count, net_write_timeout 4.27 open_files_limit, port, record_buffer 4.28 protocol_version , record_rnd_buffer, query_buffer_size 4.29 safe_show_databases, skip_networking, skip_show_databases 4.30 socket, sort_buffer, skip_show_databases 4.31 thread_cache_size, tmp_table_size, wait_timeout 4.32 SHOW PROCESSLIST syntax in MySQL 4.33 SHOW G syntax RANTS in MySQL 4.34 Syntax SHOW CREATE TABLE in MySQL 4.35 Options file my.cnf in MySQL 5.1 Column types in MySQL 5.2 Numeric types in MySQL 5.3 Date and time types in MySQL 5.4 Y2K (2000) problem and Date types in MySQL 5.5 DATETIME, DATE and TIMESTAMP types in MySQL 5.6 TIME type in MySQL 5.7 YEAR type in MySQL 5.8 String types CHAR and VARCHAR in MySQL 5.9 BLOB and TEXT string types in MySQL 5.10 ENUM string type in MySQL 5.11 SET string type in MySQL 5.12 Choosing the right type for a MySQL column 5.13 Using column types from other DBMSs for MySQL 5.14 Memory requirements of MySQL columns 6.1 Functions for MySQL usage in SELECT and WHERE 6.2 Untyped operator Brackets in MySQL 6.3 Untyped Comparison operator in MySQL 6.4 Logical operators in MySQL 6.5 Branching functions in MySQL 6.6 String functions in MySQL

MySQL is very fast, reliable and easy to use. MySQL also has a very practical set of features, developed in very close collaboration with end users. MySQL was originally designed to handle very large databases much faster than existing solutions and has been used successfully in highly demanding industrial applications.

With ongoing development, MySQL today offers a rich and very useful set of features. Simplicity, speed and reliability make MySQL very suitable for accessing databases from the Internet. Supporting truly enormous amounts of data is very important. There is a known case of using MySQL with 60,000 tables, totaling about 5000000000 rows.

MySQL is a client-server system

This means that MySQL consists of one SQL server that supports various functions (in fact, it does all the database work), several different client programs (they provide only the interface between the user and the server), administrative tools, and several programming interfaces. Clients communicate with the server using their own network protocol.

This scheme allows a large number of users to simultaneously work with the server. Including, jointly processing the same data without interfering with each other. This interaction will be discussed in detail in subsequent chapters.

Usually the client and server are used on different computers, but it is acceptable to install both parts of the package on the same computer. Even within a single computer, a network is still used to communicate between client and server. By the way, it should be noted that the client and server can run under different operating systems, this does not interfere with anything. MySQL is already available on more than a dozen operating systems.

MySQL is a fully multi-threaded system

This means that the package can easily use many processors, if any. Many server systems already have several processors installed. On such systems, MySQL can strictly execute several database queries at once (one per processor) in parallel.

MySQL is an open source package

This means that the package can easily be modified to suit your needs by anyone who is well versed in programming. Having written an important amendment to a package, such a specialist can send it to the main package site for possible inclusion in the next version. It is thanks to this development scheme that MySQL develops very quickly and takes into account the needs of end users, and all errors are eliminated in the shortest possible time. This property was perhaps the first reason for the package’s high popularity: with proper qualifications, it can be tailored to your needs.

MySQL is free in most cases

MySQL is intended for non-commercial use. If you use the package to organize a forum, guest book system or blogs, then you do not have to pay for any licenses. You just need to download the package from his website and install it on your server. But if you need technical support, then you have to pay for it. Note: The fee is charged specifically for technical support, and not for using the program itself. It is this property that has largely made this DBMS so popular.

Now we will consider in more detail the absolutely necessary terminology that will be needed in the subsequent presentation, as well as the basic principles of database operation, so that you at least have a general idea of ​​what you are dealing with. At first glance, the list of terms is long, but they will all be needed.

Since all data is stored in the form of tables, you should clearly define the type of tables and the corresponding terminology. Table comprises cells, each of which can store some data. If a cell does not currently store any data, it is called empty.

The table consists of vertical columns and horizontal rows into which cells are grouped. Table strictly rectangular, that is, all rows have the same number of cells, and all columns have the same number of rows.

Each row in the table is called recording. Each cell in the record is named record field. Since fields can store a wide variety of data, to simplify working with them, the concept type. Each cell has its own type and can only store data of the corresponding type, which must be understood when working with the system.

In MySQL, a data type is assigned to a column in a table and applies to all cells in that column. That is, if the first column is assigned a certain type (for example, char), this means that the first field of any record in this table will always be of the char type and no other.

It is very important! Most of the time you'll be working with columns because they define the data type and structure of the table. The rows in the table are not numbered; they exist only for ease of working with data. In most cases, you shouldn't care about the number of records in a table at all. You work with data, and its structure is determined by the types and order of the columns. The number of records is only important for the server.

A database can consist of several different tables. Their exact number is limited mainly by computer memory. The server can store many databases. It should be noted that you can mix tables from different databases in a single query.

The table also has type And attributes. The set of capabilities available when working with this table, as well as the logic of its processing by the server, depends on this. This will be discussed in detail later.

Now let's talk about the data in the fields. To do something with some data, you first need to find it. This is what the SQL language is used for. Queries are written on it, during the processing of which the server scans the database tables, finds the required data based on the criteria specified in the request, and does something with it (what exactly depends on the request).

The data used to search for a record is called key. If a record has several fields, then you can find it using different keys, each for its own field. The key by which a record is most likely to be searched is called primary key(PRIMARYKEY). The key can relate not only to one field, but to several at once.

One or more records can be found using one key. If only one specific record can be found using a certain key, such a key is called unique(UNIQUE). A key that is suitable for searching multiple different records in a table is called non-unique.

The next concept is index. Imagine how a database server works. Having received a request, it begins to scan the tables to find the relevant data. The scan is performed sequentially, line by line. To make sure that all the data is collected, the server must look at all the rows in the table (or tables, if the search is carried out across several tables at once).

But it's easy to say: view. What if the table contains ten thousand records? What if it's a million? The server, of course, will look at it, but how long will it take him? Quite a lot. And you need to get an answer as quickly as possible.

This is where indexes come to the rescue. Index is something like a table of contents that lists in which records certain data appears. It can be compared to searching on the Internet, where search engines store data about which pages contain certain words. Indexes in MySQL do the same thing. The index must be specially created; it is not built by itself (how exactly to create it will be discussed later).

The process of building an index takes a lot of time, but after its creation, the server no longer scans the entire table in search of data: It looks for data using an index, where for each value found in the table it is indicated in which cells of the table the necessary data can be found. This significantly speeds up the work (tens of times).

Different queries look for different data. It is often necessary to have not one, but several different indexes on a table, so that different types of queries work each with their own index, optimally created and suitable specifically for this type of query. For example, imagine a phone book. When searching for a subscriber's last name, the index must indicate in which records to look for a particular last name. But if the search is carried out by name, then the index should be built not by last names, but by the names of subscribers.

It turns out that sometimes you need to have several different indexes for each table. In MySQL you can have up to 32 indexes per table. Maximum index length(that is, the length of each entry in the index) is up to 500 bytes. An index can include data from multiple columns at once (in the current MySQL implementation, the maximum number of columns in each index is 15).

Since indexes are built on the data in the fields of records, and each field can be considered as a key, it is said that the index is built by keys. An index built on primary keys will be used in searches with the highest probability and is called primary index.

All columns have default values. This means that if a field is not explicitly given a value, it will be automatically set to some default value specific to each column type. The default value can be changed when creating a column.

Each column in the table has unique name. Tables and databases also have names. In a number of cases, which will be discussed below, a column must have several names. In this case, only the one assigned to the column when it was created is considered a name; the rest are called aliases. There are also aliases for table names.

Columns are not necessarily created with tables. The table can be changed as needed by adding or removing columns or changing their types. In SQL statements, you can access tables from different databases using the syntax Database_name.Table_name. This long name allows you to uniquely identify the table and is called fully qualified table name.

You can also refer to a column in any table by specifying the syntax Database_name.Table_name.Column_name. This design allows you to uniquely identify the column and is called complete column name.

In addition to name and type, columns can also have optional attributes, which determine exactly how the server processes a particular column, change the logic of how the server works with this column. Assigning an attribute to a column is equivalent to assigning that attribute to the column's corresponding field in each record in the table. Note that columns of the same type, but with different attributes, are processed in different ways.

When working with a DBMS, some database is always considered active or current. There is a certain active table. It is with the active table in the current database that all actions will be performed, unless you explicitly indicate otherwise.

When accessing a column in the active table, you can specify only the column name instead of its full name (indicating the database and table). It will automatically be supplemented with the name of the active table of the current database, which significantly speeds up the input process. Also, if you are accessing a column from another table in the current database, you can specify its name as Table_name.Column_name, omitting part Database_name. it will be set to the current database.

In the following discussion you will come across the concept of flow. Flow in this represents your connection to the database server. All commands you enter apply only to this thread. Please note that if you have created several different connections to the same database (for example, by opening several copies of the client), then each connection will be a completely independent thread, in no way dependent on the others. This is the big difference between a user and a thread: one user can be represented by several independent threads. Later we will show what pitfalls this can lead to.

Wildcards or wildcards represent symbols that can correspond to a certain number of other symbols. For example, when working in Windows, you've most likely encountered the asterisk (*) character, which denotes any string of arbitrary characters. This method is widely used when working with groups of files. This is the wildcard.

Regular Expressions represent certain sequences of characters, some or all of which are wildcards. For example, when working in Windows, you most likely came across notations like *.doc (matches all files with a doc extension in the current directory) or *.* (matches all files in the directory). These are regular expressions, only they are called differently in Windows. As you can see, there is nothing complicated about them. In MySQL, you will come across such expressions more than once (though a little more complex). It is with their help that the criteria for searching for information are set.

Now let's think about this complex problem: a server allows multiple users to work simultaneously on the same database (even the same table). But how to ensure data integrity? If one user writes some data, and another at the same time tries to change this particular data, they will destroy the entire database. How to avoid this?

There are two ways to set partitioning, and MySQL uses both, albeit on different types of tables. The first one is transaction model, second atomic modifications.

Transaction refers to a certain database operation that cannot be divided into several separate operations. A full description of the two concepts listed above is very complex and seems unnecessary in this book, so we will consider them only from the user's point of view.

So what does working with a transaction look like? The server presents it this way: first, it is determined what exactly will be changed in the table, then a mark is made that these cells are changing in some way, then the changes are actually made, and then a mark is made that the modification has been completed. At the same time, while changes are being made, the table either returns old data or returns nothing at all, but in any case, it does not allow two users to simultaneously make changes to the same data. First, the first one finishes the modification, then the next one takes over.

The difference between a transaction and an atomic modification, all scientific theory aside, for the end user is that in the case of a transactional model, the user can, after executing a query that changes some data in a table, decide exactly how he wants to complete the transaction: should whether save changes (commit) or Refuse them (call rewind, rollback), thereby returning the table to the state it had before calling the query. It should be noted that there is a mode for automatically saving all changes (AUTO_COMMIT). In the atomic model, changes cannot be undone: they are entered into the table immediately. The transaction currently in progress is called active.

MySQL uses its own table format by default: MyISAM. Previously, the proprietary ISAM format was also used, but it has now been declared obsolete and is supported solely for compatibility with older users. If you have tables in this format, we highly recommend converting them to the new MyISAM format. It works more reliably and faster.

Since we are talking about supported table formats, we should immediately clarify that MySQL supports several different formats. Some work on a transaction basis, others on atomic modifications, so that the end user always has a choice of what to use. It should be noted that the transactional model is much more complex to implement than the atomic one, and therefore support for transactions in MySQL appeared much later. MySQL formats (MyISAM and ISAM) use atomic modifications, but they implement them so well that in terms of reliability they are in no way inferior to the transactional access model. In table 1.1. lists the table types supported by MySQL with their brief descriptions.

Table 1.1. Brief descriptions of MySQL supported table types.

Please note that not all server versions support all tables listed! The ISAM and MyISAM types are always supported, but there are options for the rest. So take a look at http://www.mysql.com to see what exactly you need.

A dump is an intermediate representation of a database. Moreover, it is usually specified which data representation is meant. For example, dump to text file means that the entire database is converted and saved as a text file.

Why is this necessary? Dumps are very convenient for backup, as well as for transferring data between different servers. It may be necessary to apply the dump within the same server.

Table 1.1 shows the different types of tables. Each of them has its own internal data storage format. The easiest way to convert one to another comes down to dumps.

MySQL is one of the easiest databases to administer on all platforms. In addition, this database does not require resources, so it can be used even on personal computers with a small amount of RAM and hard disk. Because of this, PHP developers have long used MySQL to create a complete local web development environment on all types of client computers, even laptops.

Any developer working in the PHP environment is able to independently administer a MySQL database, unlike some other databases. To further simplify the task of administration, you can take advantage of numerous tools that are not only provided in the MySQL database itself, but can also be obtained from third-party developers.

The main concepts that you should become familiar with at this stage are:

  • database- container for the entire MySQL data collection;
  • table- a container nested in the database in which the data itself is stored;
  • line- a separate record that may contain several fields;
  • column- field name inside the line.

It should be noted that I am not trying to reproduce the exact terminology used in educational literature on relational databases, but rather to provide simple, common definitions to help you quickly understand the basic concepts and get started working with the database.

Accessing MySQL from the command line

There are three main ways to work with MySQL: using the command line, using a web interface like phpMyAdmin, and using a programming language like PHP. The third of these methods will be discussed in subsequent articles, but now let's look at the first two methods.

If you have installed the OpenServer WAMP server in accordance with the instructions in the article, then you can access the MySQL executable program from the following directory:

MySQL course from scratch.

Instead of MySQL-5.7-x64 you need to substitute the version specified in the OpenServer settings in the "Modules" tab.

You need to open the Command Prompt program and go to this directory. This is done using the command cd PATH_TO_NEEDED_FOLDER:

The code is only available after purchasing the MySQL from scratch course.

After this, you need to run the mysql.exe program in this directory, passing its special parameter. To do this, you now need to run the command on the command line:

The code is only available after purchasing the MySQL from scratch course.

As a result, the MySQL client will start. It is connected to the MySQL server, which was launched when OpenServer started.

If this does not lead to the desired result and you receive an error message about connecting to the MySQL server "Can"t connect to MySQL server on "localhost"", make sure that OpenServer is running and MySQL is specified in the modules.

The -u parameter stands for user. That is, this is a checkbox for specifying the user under which you want to connect to the server. root is the most important user in MySQL. It is created when the server is installed and by default it does not have a password.

But let's return to our terminal. Through this console client we can send various commands to the server. Let's run a command that lists all the databases created on this server.

The code is only available after purchasing the MySQL from scratch course.

In response, we will receive a beautifully designed list of databases. You will have fewer of them than I do, because I have already added them.

Working with MySQL via phpMyAdmin

To manage databases and tables it will be much easier and faster to use the phpMyAdmin program. Before entering the following line into the address bar of your browser, you need to make sure that the OpenServer program is already running and, therefore, the MySQL database is ready for use:

Here we will be greeted by such a beautiful window for logging into the system.

Just as in the case of a console application, specify the root user and leave the password blank. Click "login".

After this, you will be taken to the database control panel with a fairly friendly interface. On the left you will see the same list of databases that you received in the console version. You can poke them and see what’s inside.

Now let's click on the SQL tab and go to the window where you can directly write queries to the MySQL DBMS, as it would be in the console:

In the window that opens, enter the same query:

The code is only available after purchasing the MySQL from scratch course.

We press the “forward” button and see the same result as in the case of the console application.

Basic SQL Concepts

According to Andrew Taylor, who developed the SQL language, the name of the language is not short for Structured Query Language (or anything similar), although many believe that it is. SQL is the basis for a stricter and more general method of storing data than the previous DBM-style database organization standard, which was based on the use of flat files.

SQL language is defined by standards ANSI(American National Standards Institute) and ECMA(European Computer Manufacturer's Association); both of these standardization organizations are internationally recognized. But it should be borne in mind that in the general recommendations of SQL standards there are noticeable differences regarding software products of commercial companies, on the one hand, and organizations involved in developing databases with open source, on the other hand. For example, over the past few years there has been a rapid development of so-called object-relational databases, as well as SQL software products specifically designed for the web market. The list of databases that can be used in combination with a PHP system is extremely large. is large, so certain principles must be followed when choosing the most suitable database.

The basic principle is that you must first consider your own development needs, or at least know exactly what goal you want to achieve. If you try to read other recommendations, you will come across a lot of very convincing messages with such arguments that you literally “cannot do” without some advanced database tools (such as triggers or stored procedures) and any SQL-enabled software product that does not have these tools hardly deserves the right to be called a SQL product. Take these judgments with a grain of salt. It is much better to make a list of the required characteristics yourself, in order of importance, and then start searching for the software product that best suits your requirements.

But despite the above, much of the SQL language support does follow the standard. Therefore, programs typically use only a few SQL statements repeatedly, regardless of which specific software product is chosen to be implemented.

Essentially, a SQL database has a very simple logical structure. Any given SQL software installation can typically consist of multiple databases. For example, one database can be used to store data about customers, and another can contain data about products. (A certain complication arises because the SQL server itself and the collections of tables it supports are usually referred to by the general term database.) Each database contains several tables, each table consists of carefully defined columns, and each position in the table can be considered as a record or row entered into a table.

Any SQL server supports four so-called data manipulation statements, and in general these statements underlie the vast majority of operations performed on a relational database. These four basic database statements are SELECT, INSERT, UPDATE and DELETE. SQL statements, also called commands, are very convenient and allow you to perform almost all necessary actions in the database.

An important feature of these four SQL statements is that they only manipulate values ​​stored in the database, but do not affect the structure of the database itself. In other words, commands based on these operators can be used, for example, to enter data rather than to create a database; Using such commands, you can remove any piece of data from the database, but the “shell” itself will remain intact, so, in particular, you cannot assign the name of an existing database to another database running on the same server. To add or remove columns, destroy an entire database without leaving a trace, or create a new database, you must use other commands such as DROP, ALTER, and CREATE.

We will look at all these operators in detail in the next article on MySQL commands.

From the author: Did they call you a teapot? Well, this matter can be fixed! Every samovar was once a teapot! Or was every professional once a samovar? No, something is wrong again! In general, MySQL is for beginners.

Why do dummies need MySQL?

If you are seriously planning to connect your life with the Internet, then right from the very first steps in the “web” you will come across this DBMS. MySQL can easily be called the “all-Internet” database management system. Not a single more or less serious resource can do without it; it is present in the admin panel of every hosting. And most of all popular CMS and even “homemade” engines are built with its participation.

In general, you cannot do without this platform. But to study it you will also need the right approach, the right tools, and most importantly desire and patience. I hope you have enough of the last ingredients. And be prepared for your brains to boil and steam to pour out of your head, like from a real kettle

But MySQL is so difficult for dummies only if you start learning it incorrectly. You and I will not make such a mistake, and we will begin our acquaintance with this technology from the very beginning.

Basic Concepts

First, let's go over the basic concepts that we will mention in this publication:

Database (DB) is the main component unit of a DBMS. The database includes tables that consist of columns and records (rows). The cells formed at the intersection contain structured data of a certain type.

DBMS (database management system) is a set of all software modules for database administration.

SQL is a structured query language with which the developer “communicates” with the DBMS core (server). Like any programming language, SQL has its own syntax, set of commands and operators, and supported data types.

I think that theoretical knowledge is enough for us to start with. We will “color in” the missing gaps in theory with practice. Now all that's left is to choose the right software tool.

Selecting the right tool

Having rummaged through the entire range of MySQL shells for beginners, I realized that they simply do not exist. All software products for DBMS administration require an already installed database server. In general, I decided once again not to invent the “scooter”, and opted for the domestic Denwer package. You can download it on the official website.

It already includes all the components of a DBMS, allowing a beginner to begin a practical acquaintance with MySQL immediately after a simple and straightforward installation. In addition, Denwer includes several more tools necessary for a novice developer: local server, PHP.

First steps

I will not describe the installation process of the “gentleman’s” set, since everything happens automatically there. After launching the installation, only have time to press the necessary keys. Just what you need in the MySQL for dummies version.

When the installation process is completed, start the local server, wait a couple of seconds. After that, type localhost in the address bar of your browser.

On the page “Hurray, it’s working!” follow one of the links shown in the picture. After which you will be taken to phpMyAdmin - a shell for administering databases.

By following the link http://downloads.mysql.com/docs/world.sql.zip, you will download an example test database from the official MySQL website. Go to phpMyAdmin again, in the main menu at the top, go to the “Import” tab. In the Import to Current window, in the first section (File to Import), set the value to Browse your computer.

In the Explorer window, select the archive with the downloaded example database. Don't forget to click "Ok" at the bottom of the main window.

I advise you not to change the specified parameter values ​​for now. This may result in incorrect display of the imported source data. If the phpMyAdmin system generates an error that it cannot recognize the database compression algorithm, then unzip it and repeat the entire import process from the beginning.

If everything went well, then a program message will appear at the top that the import was successful, and on the left in the list of databases there will be another one (word).

Let's look at its structure from the inside so that you can more clearly imagine what you have to deal with.

Click on the name of the MySQL database for beginners. A list of tables that it consists of will be displayed below it. Click on one of them. Then go to the top menu item “Structure”. The main work area will display the table structure: names of all columns, data types and all attributes.