Tag Archives: mysql

Solve MySQL error 2002 (HY000)

Error 2002 (HY000): can’t connect to local MySQL server through socket ‘/ var/run/mysqld/ mysqld.sock ’ (2)

When starting mysql, it appears:

because I haven’t used MySQL under Ubuntu for a long time, I thought my password was wrong, and I repeatedly lost it several times. I found that it’s still like this. I also checked the related blogs on the Internet and found that it can’t work. Generally, this kind of error appears on the Internet, which is a bit similar to

In fact, it’s not the same. Pay attention to distinguish the following folders, so go to the configuration file of Mysql to see where the socket folder is, and the configuration file of MySQL is in
/etc/MySQL/ my.cnf In this, cat has a look:

found this sentence remember to edit So when you install mysql, the MySQL Server package is not installed (I don’t know how to get in before, ha ha), so you can install this package

you can also check whether there is this package first

so after installing mysql-server-5.7, you can enter the root password.
A289885427
now my.cnf There is no previous sentence

An error keyerror255 was reported when pymysql connect to MySQL

Contents of articles

Solutions for error reporting

abstract

Pymysql connect to MySQL reported an error of keyerror255. Recently, I was trapped for more than two months by a difficult problem. If you search this title, you can see that the search engine has provided n ^ 2 articles on solutions. Why do you still trap me for so long?Don’t I know Baidu?NO NO NO!! The biggest problem is that my executive computer and data storage computer are not the same computer!!

Error information

  File "D:\Programfiles\Anaconda3\lib\site-packages\pymysql\connections.py", line 1269, in _get_server_information
    self.server_charset = charset_by_id(lang).name
  File "D:\Programfiles\Anaconda3\lib\site-packages\pymysql\charset.py", line 38, in by_id
    return self._by_id[id]
KeyError: 255

The main reason is that MySQL 8.0 updates many character sets, but these character sets are longer than 255 , so the old version of pymysql does not support characters longer than 255

Online can find a lot of articles to solve this problem, consistent solution, update pymysql

pip install --upgrade pymysql

The following casually put a, interested can see, don't look also doesn't matter, full text summary on a sentence update pymysql, directly execute the above update code, if solve, OK! All is well, you can quit, but you can't solve it. The link article is not meaningful. Let's continue to read my text

Django appears after changing the default database SQLite3 to pymsql Keyerror:255 How to upgrade pymysql

Solution

As mentioned before, my executive computer and data storage computer are not the same computer!!
My own computer is mysql5.7, and the data storage computer version is 8.1
because at the beginning, the company's network security was upgraded to a secondary level, and then the company's intranet VPN was updated once (big exchange, the interface is different),
so at the beginning, I thought it was caused by the network security policy,
after all, all the online updates are pymysql, I'm already up-to-date and can't update any more

In fact, the solution is in a word, too lazy to beat around the bush so many words

uninstall and reload MySQL

yes! You're right! Is the MySQL database to unload, and then re install a version of 8.0 and above

So the main reason is that at the beginning MySQL 8.0 has updated many character sets, but the length of these character sets exceeds 255


Write in the last canvassing session
recently participated in the CSDN official organization of "geek +" original blogger competition
after many screening, finally on the top 50
original is not easy, help cast a free vote
support: Click to vote
thank you!!!

[error handling] when logging into MySQL with CentOS command, an error 1045 (28000) is reported

When logging into MySQL with CentOS command, error 1045 (28000): access denied for user is reported root@localhost (using password: no) error resolution

1. Disable MySQL service: #/etc/RC. D/init. D/mysqld stop

2. Input command: #/mysqld_ Safe — user = MySQL — skip grant tables — skip Networking & amp;

3. Log in to the database: # MySQL – U root MySQL

4. MySQL & gt; use MySQL; the results are as follows:

database changed 5. MySQL & gt; update user set password = password (‘newpassword ‘) where user’ =’newuser ‘; the results are as follows:

query OK, 3 rows affected (0.00 sec) rows matched: 3 changed: 3 warnings: 0

MySQL & gt; flush priorities;

the results are as follows:

query OK, 0 rows affected (0.00 sec)

MySQL & gt; quit

;/etc/RC. D/init. D/MySQL D restart

MySQL – u newuser – P

Enter password:newpassword

 

mysql> ≪ login successful & gt;

Error 1064 in MySQL password change

MySQL must know P203 to change the password

mysql> SET password for ben=password('123456');

Error will be reported during operation

ERROR 1064 (42000): You have an error inyour SQL syntax; check the manual that

corresponds to your MySQL server versionfor the right syntax to use near ‘passw

ord(‘123456′)’ at line 1

The reason is that after MySQL 5.7.6, the password property has been cancelled (select password is used)

(the “123” experiment informs that an error is reported), and the statement to modify the user’s password has changed

 

Correct statement:

mysql> alter user ben identified by'123456';

Query OK, 0 rows affected (0.15 sec)

 

reference material: https://www.zhihu.com/question/30481083

(maybe there are other solutions, just share the mistakes in learning and my solutions. If there are mistakes in the above statements, please criticize and correct them. Thank you.)

Solution to error 2002 (HY000) in MySQL

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/ mysql.sock ‘ (111)

Troubleshooting:

1. Start the service: Service mysqld status
2. Open the port: lsof – I: 3306
3. Determine the correct location of the “socket” file: lsof – C mysqld | grep socket $
find/- name “*. Socket”

MySQL server PID file could not be found!

Error content:

ERROR! MySQL server PID file could not be found!

Error report screenshot:

MySQL version 8.0

 

Additional:

https://blog.csdn.net/qq_ 31708763/article/details/104375300

Adding configuration files to MySQL on MAC my.cnf : https://blog.csdn.net/qq_ 31708763/article/details/104357798

SQL query time group_ Was cut by group_ CONCAT()

 

When querying MySQL database, use group_ “Row XXX was cut by group_ Concat () “, check it out because of group_ There is a limit on the maximum length of concat. If it exceeds the maximum length, it will be truncated,

Let’s check the global environment variables of MySQL

mysql> SELECT @@global.group_concat_max_len;
+-------------------------------+
| @@global.group_concat_max_len |
+-------------------------------+
|                          1024 |
+-------------------------------+

Check the maximum length of the query field in the production environment

mysql> select max(length(extra)) from credit.apply;
+--------------------+
| max(length(extra)) |
+--------------------+
|               9599 |
+--------------------+

Check the maximum number of aggregations again

mysql> select max(c1) from (select custid,count(1) as c1 from  credit.apply group by custid )t;
+---------+
| max(c1) |
+---------+
|      58 |
+---------+

So it is estimated that the maximum possible length is

9599 *58+67=556809

You can change the group_ concat_ max_ Len variable solves the problem

SET group_concat_max_len=556809;

 

MySQL settings group_ concat_ max_ len

 

GROUP_ The concat function is used to connect multiple strings into a string. When splicing into a string, there will be the problem of splicing length. The default splicing length of MySQL is 1024 bytes. Because 1024 bytes will not be enough, sometimes it needs to be modified according to the situation. The method is as follows.

 

1. View the current MySQL group_ concat_ max_ len

Enter the MySQL state and enter: Show variables like ‘group_ concat_ max_ len’;

If it has not been modified, you will get the following result

2. Modify MySQL group_ concat_ max_ len

a) , if it is not convenient to restart mysql, you can set it in the MySQL state through the command, such as:

 
    SET GLOBAL group_ concat_ max_ len = 102400;   SET SESSION group_ concat_ max_ len = 102400;

 

Check through mode 1.

Note: in this way, the configuration file will be read and reset after the restart of MySQL, which will lead to invalid settings, so it is recommended to modify the configuration file

b) , modify configuration file: my.ini

Add a new configuration under [mysqld]: group_ concat_ max_ len = 102400

Restart and view through mode 1.

In particular, sometimes we don’t know how many bytes we need to meet the requirements. In this case, we can consider not setting the maximum number of bytes (that is, using the maximum number of bytes), that is, setting group in the configuration file_ concat_ max_ len=-1

In this case, you can view the results in mode 1 as follows:

Note: 4294967295 = 2 ^ 32 – 1

This function has none of deterministic, no SQL, or reads SQL data in its error records

This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_ bin_ trust_ function_ creators variable)

The solution to this error when creating a function in MySQL:
set global log_ bin_ trust_ function_ Creators = true;
it should be noted that it is invalid after restarting the service.

MySQL error: 1005 can’t create table (error: 150)

Cause of error:

1. The type or size of the two fields do not strictly match. For example, if one of them is int (10), then the foreign key must also be set to int (10), not int (11), and it cannot be tinyint. You can use the show command to view the size of the field, because some query browsers sometimes display int (10) and int (11) as integer. In addition, it is necessary to confirm whether both fields are signed or not, and the two fields must be strictly matched all the time.

2. When an attempt is made to refer to one of the foreign keys, which is not indexed or is not primary key, an index must be created for this foreign key.

3. The name of a foreign key is an existing key value. You should make sure that the foreign key name is unique, or add several characters randomly after the key name to test whether this is the reason.

4. If you want to use foreign key constraints, one or two of the tables representing the MyISAM engine must be InnoDB engine (if both tables are MyISAM engines, this error will not occur at all, but foreign keys will not be generated).

5. It is possible that on delete set null is set, but the related key field is set to not null. You can fix this bug by modifying the property value of cascade or setting the field property to allow null.

6. Make sure your charset and collate options are consistent at the table and field levels.

7. A default value may be set for the foreign key, such as default = 0

8. In this relationship, one of the fields is one of the mixed key values. It does not have its own independent index, so it is necessary to create an independent index for it.

9. Error in alert declaration.

10. The two tables to be joined have different encoding formats.

Refer to Baidu document: https://wenku.baidu.com/view/7a0a1f1b10a6f524ccbf85e6.html

[How to Fix] MySQL Workbench for Mac Flashback

After MySQL workbench 8.0.23 Mac version is installed successfully, double-click to open and flash back

Start at the command line and you can see the error:

Fatal Python error: initfsencoding: unable to load the file system codec, sys.path = ['/Users/georgi/Applications/MySQLWorkbench.app/Contents/Resources/libraries', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload']
ModuleNotFoundError: No module named 'encodings'

The reason is python

Solution:

1. Scheme 1: command line startup

PYTHONPATH=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7 /Applications/MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench

2. Scheme 2: modify the MySQL workbench running file

cd /Applications/MySQLWorkbench.app/Contents/MacOS
mv MySQLWorkbench MySQLWorkbench.bak
echo "PYTHONPATH=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7 /Applications/MySQLWorkbench.app/Contents/MacOS/MySQLWorkbench.bak" > MySQLWorkbench
chmod +x MySQLWorkbench

After executing the above commands, double-click MySQL workbench to start normally

reference resources: https://bugs.mysql.com/bug.php?id=102364

About MySQL 1058 error

When I used MySQL a few days ago, it was still normal, but today I find that MySQL can’t be started. The prompt of using net start MySQL command is as follows:

   

Then I found that there was no MySQL content in the registry, and the MySQL service could not find the path. So mysqld – remove, the MySQL service was deleted successfully, and then mysqld – install, but it prompted that the MySQL service already existed. Next, I use the net start MySQL command. This time, the prompt becomes error 1058, that is, the service cannot be started. The reason may be that the service has been disabled or the device associated with it has not been started.

Then, through Baidu found a solution, in the MySQL configuration file, my name is my.ini Add the following content to the configuration file:

Finally, the service mysqld – install is re installed to prompt that the service is installed successfully. Then start MySQL (net start MySQL) to run normally.

This program cannot be started because vcruntime140 is missing from your computer_ 1.dll。 Try to install the program again to solve the problem.

In the process of installing mysql8, this error is encountered

 

Solution: go to Microsoft official website to download and install visual C++

Download address: https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

Here you can choose according to the number of digits of your computer

After downloading, install. After the installation is successful, there will be vcruntime140 in the directory of C: [windows] system32_ 1.dll file

If you continue to install mysql, no error will be reported