MySQL commands How to activate them correctly?

If you have had any problem managing a database from another server, don't worry, today we are going to tell you everything related to MYSQL commands.

mysql-2-commands

MYSQL commands

Talking about these types of formats and commands is simply taking into consideration the way in which a database will be inserted into a web page. It is important to know how to enter MYSQL commands through a file medium, as well as through a terminal.

The query for the database is vital for the operation of any system. The use is generally done through the PHP page, but the handling is convenient to do it using the PhpMyAdmin program; However, it happens that if there are problems, the most viable alternative is to enter them through a command line.

In the same way, if we are on a distant server and access through the terminal, it is necessary to use that tool to recover these files. Today we will give you some instructions so that you can know how this process is carried out.

Locate the file

MySQL files are used through a client software, with which it shares the same denominative, MySQL. It is used in most cases to control the database through the command line; They are operative when different file programming is carried out and MySQL commands.

In any device that has the Windows software installed, this file can be obtained, its location is at the following address: C: Program filesMySQLMySQL Server 4.1bin.

You can also get it in C: xamppmysql; this directory may be different but only in name.

On windows

For example, sometimes and depending on the version of the Windows operating system, it is located on disk C: or in any other place within the memory of the computer, likewise, it can be located in another link where the programmer has decided to insert it. It depends a lot on what type of program was used to install it.

But do not worry about the search, using Google engines they can be found easily, especially getting the correct folder, since sometimes the computer's own search engine does not offer the information we need.

mysql-3-commands

The correct folder or the one you want to manage is located as directed by Google. For example, if we are on Windows and we want to access the MySQL alternative, we locate ourselves within the directory or place the folder within the PATH configuration.

On Linux

We know the ease that Linux offers to all programmers and developers, although this does not mean that it is easier to access MySQL files, it is easy to do it through the command lines; it can also be accessed from any other directory.

So when the database engine is placed, the same system provides the "MySQL" file, regardless of which folder we are in, hence the ease of Linux to carry out this action.

On Mac

Some think that this system is always somewhat different compared to its rivals Windows and Linux, but it is interesting to know that on Mac it depends a lot on how the MySQL file is installed on the computer. In this case, the command is not directly available as in Linux or Windows, even with the database engine configured.

To do this, we must do a search on Google, which will offer us all the information we need to locate it on the computer and directly access the "MySQL" file. A configuration that is carried out in this type of files is the use in the installation of the Mamp program; the immediate answer of the system will be FAQ, which will help us to use the command "mysql" on Mac and install it with Mamp server.

mysql-4-commands

Connect to MySQL server

After locating the MySQL file, you must connect to the manager through the command line. Then proceed to invoke MySQL, placing the identifier of the file with the same name and indicating the basic connection options.

If we put «% mysql», we will get access to the command line and from there we can avoid the prompt origin, however by putting; c: mysqlbin>. We directly ignore the "%" character.

The indication connects with the database according to the parameters and conditions that the program has by default. Inserting and binding the local server with username or password in empty strings; Then you must enter another piece of information to be able to connect to the database, for example, place the following parameters: mysql -h server_name -u username -p.

Now, if we want to connect the database to the local server using the root user name, we should write the following: mysql -h localhost -u root -p, in this sense the system requests the password for that type of root user . After introduced, we enter the MySQL command line; so the prompt changes to the following: mysql>

In case of indicating the password directly on the command line, an immediate entry could be made, but it is not advisable for security reasons, in this case the command would be: mysql -h localhost -u root -pmi_key, enter the - py the my_key should not leave any spaces unless you are on a local server.

These programming processes are important in each operating system, if you want to obtain more information related to this topic, we invite you to read the following article While in programming 

Using the MySQL console

After we are inside the console, we have at our disposal all the alternatives of the MySQL command, which allows us to manage and carry out any activity with the database and the SQL code. However, it should be normal to connect to a main database first, to have the option of working more safely.

Consequently, the "use" command must be used followed by the name of the database that we want to connect, let's see the example: mysql> use my database; we then enter the "mybaseddata" database. However, we must take into account all the statements which must be within the MySQL command line.

Each one ends in ";". So if we do not place that semicolon, the command will not be executed and therefore the command prompt will appear again, which is an indication that we must continue entering sentences.

However, if we only want to execute the statement that we had previously selected just by placing «;» It will be enough. For this reason, the complete command should not be typed again and it only indicates ";" and hit enter.

Database list

To select a specific database we must perform an action, which will allow us to see which ones are available; for this we must put the following syntax: mysql> show databases; A list appears with all the databases found on our computer. And at the end the following is shown: mysql> show databases ->; 5 rows in set (0.02 sec).

Create a database

Remember that we are inside the Mysql file, which is giving us the resources to perform various actions related to databases, something that is necessary to migrate, manage and upload information to any server. If we want to create a database, we must do the following:

Write "create database", accompanied by the name we want to put to the new database, let's see: mysql> create database example; this creates the file.

That will create a database called "example", which will be registered in MySQL, and we can use it later, so if we want to use it in the future we carry out the following action: mysql> use example.

Database managment

This database is idle since it has just been created, but if we were using an already used database, we must write its name. Also, if we want to use or see the tables that compose it, we must write "show tables", let's see: mysql> show tables.

In this sense, the database does not contain tables, information like this immediately appears: "Empty set". On the contrary, if there are several tables within the same file, the list of tables will appear accompanied by the following: 2 rows in set (0.00 sec).

To get data related to a specific one and also know what areas are available, as well as the class, we must use a command which describes the specification and the name of the table, like the following: mysql> description of the administrator. 3 rows in set (0.11 sec).

If you want to know more about this and other topics, we recommend reading the following article PowerShell commands where you will get additional information related to this topic

Other Actions and Judgments

While in the MySQL console, indications can be made through the command lines: In this sense, any type of code can be requested using SQL; there we can make choices, updates, table creation and insertions.

The way to do it is simple, especially if you know some programming, the process is intuitive and easy to deduce, we just have to execute the sentence immediately after placing a semicolon. Let's see an example:

  • mysql> create table test (test id int);
  • Query OK, 0 rows affected (0.08 sec).
  • You can also use the following: mysql> insert into test (test id) values ​​(1);
  • Query OK, 1 row affected (0.00 sec).

Finally, we hope to have resolved some doubts related to this issue of the MySQL database, which is very helpful for companies and organizations, if you want to obtain more information about it, do not forget to know and read other contents that are in our portal.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Actualidad Blog
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.