Mysql installation and troubleshooting in Linux, linuxmysql

Source: Internet
Author: User

Mysql installation and troubleshooting in Linux, linuxmysql

1. Install Mysql

 

Environment:

 

Mysql version:

Start installation:

First, check whether there are any old mysql versions in the environment. If yes, uninstall them first.

Then first obtain the mysql installation package: wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

If FTP is used

Then install: yum localinstall-y mysql57-community-release-el7-11.noarch.rpm

Install the following service: yum install-y mysql-community-server.

After installation, enable the service: systemctl start mysqld. service

1.1 problem: if the newly installed mysql service is enabled

View mysql-related processes:

Then kill it. If you enable it again, the following situations will indicate that it is okay:

Note that the line active (running) is green.

If this occurs when you view the mysql status:

It indicates that the error occurred.

Restart mysql: systemctl restart mysqld. service.

Then, if this happens:

The configuration file may be faulty. The following describes how to change the configuration file. (The newly installed mysql configuration file is normal. The problem may be caused by a mysql process .)
2. Enter Mysql

 

After the installation, mysql will give you a default random password. At this time, you need to change the root password and permissions so that you can connect to mysql for data operations later.

Here are two methods to change the password:

First, add skip-grant-tables to the configuration file. This is a direct bypass of Logon. The disadvantage is that this method is recommended to be temporary and will not be applicable for a long time. Considering that the database needs to be opened later.

Enter vim/etc/my. cnf to edit the mysql configuration file. Then change (by I ):


This is almost the case. We add skip-grant-tables to the cursor, that is, under the top [mysqld]. Note that it is mysqld and there is an msql above.

Press esc and enter the colon + wq to save and exit: wq

Then, restart mysql and directly enter mysql to log on directly.

Next, we need to change the mysql password. First, let's take a look at the database: show databases;

We can see that there is a mysql database, which exists after installation. We use this database: use mysql;

There is a user table in this database, which stores login-related fields in the table. We only need to update the table:

Mysql> update user set password = password ('000000') where user = 'root' and host = 'localhost ';
Mysql> flush privileges;

Generally, there is no problem.

In this case, there is no password field in your user table. (This was the case at the time.) Don't worry. Let's take a look at the fields in the user: desc use;

After reading the fields one by one, you can see that the password field does not exist.

However, you can find this field.

This field stores the default encrypted password of mysql.

Let's take a look at the select:

You can simply update the field to your password. (After changing the password, remember to delete the skip in the configuration file and restart mysql)

The second is to view the log, which will tell you the default mysql password. Each machine is different. Let's take a look: grep 'temporary password'/var/log/mysqld. log

Knowing the default password, we can log on and change it to our own password (the password is at the end of the root @ localhost: Here. You can also use his random password.: D ).

3. Connect to Mysql

 

When Navicat for Mysql is used for the first time, 1130 host is not allowed to connect to... may occur .... This error

The reason is that your account is not allowed to log on remotely, but only on localhost. You only need to change the table data.

After logging on to mysql, use the mysql database, and then enter

Mysql> update user set host = '%' where user = 'root ';

Mysql> flush privileges;

Don't worry.

Mysql> select host, user from user;

You can see that the root user's host field is changed to %.

4. When inserting Chinese Characters in mysql, why ?? Or garbled; Chinese data is inserted after mysql is connected in myeclipse.

 

In this case, first make sure that your development environment is all UTF-8 (to be consistent with mysql) including the IDE and Navicat for mysql encoding.

Then, modify the mysql configuration file:

First, let's take a look at the database encoding. Input: show variables like '% char % ';

I have modified it here. The default value has another encoding. First, we need to update their encoding:

SET character_set_client = utf8;

SET character_set_connection = utf8;

SET character_set_database = utf8;

SET character_set_results = utf8;

SET character_set_server = utf8 ;.

....

After modification, the mysql encoding may be restored after restart. At this time, you need to change the my. cnf configuration file (the default path is/etc/my. cnf ).

Exit mysql and enter vim/etc/my. cnf to enter the editing mode by I.

Add the above two lines of code. Note that the line at the cursor should be placed under [mysql], and the bottom should be placed under [mysqld. At the beginning, I put the wrong position, causing a problem when I restarted mysql:

This Job for mysqld. service failed may occur.

Restart mysql after modification.

5. Conclusion

 

These problems have been encountered during their own struggles. Some of them have headaches and may be difficult to solve during the afternoon. After searching, the Experts finally solved all the problems. I wrote this article to summarize the problems I encountered during installation. I hope it will help new users who have just started to deploy mysql in linux.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.