REQUEST COMPLIMENTARY SQLS*PLUS LICENCE
Fix typical errors in MySQL
MySQL is an open-source database management system (DBMS) from Oracle. It was developed and optimized specifically for web applications. MySQL is an integral part of such web services as Facebook, Twitter, Wikipedia, YouTube, and many others.
This article will tell you how to identify and fix common MySQL server errors.
Can’t connect to the local server
One of the common mistakes of connecting client to server is “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld.sock’ (2)”.
This error means that the MySQL server (mysqld) is not running on the host or you specified the wrong Unix socket file name or TCP/IP port when trying to connect.
Make sure that the server is running. Check the process with the name mysqld on the server host using ps or grep as shown below.
$ ps xa | grep mysqld | grep -v mysqld
If these commands do not show output data, the database server does not work. Therefore, the client can’t connect to it. To start the server, execute the systemctl command.
$ sudo systemctl start mysql #Debian/Ubuntu
$ sudo systemctl start mysqld #RHEL/CentOS/Ted
To check the status of MySQL service, use the following command:
$ sudo systemctl status mysql #Debian/Ubuntu
$ sudo systemctl status mysqld #RHEL/CentOS/Ted
If a MySQL service error occurs as a result of the command execution, you can try to restart the service and check its status again.
$ sudo systemctl restart mysql
$ sudo systemctl status mysql
If the server is running (as shown) and you still see this error, you should check if the TCP/IP port is blocked by the firewall or any other port blocking service.
Use the netstat command to find the port that the server is listening to.
$ sudo netstat -tlpn | grep "mysql"
Can’t connect to MySQL server
Another similar and common connection error is “(2003) Can’t connect to MySQL server on ‘server’ (10061)”. This means that the network connection was denied.
You should check if the MySQL server is running in the system (see above) and if you connect to that port (you can see above how to find the port).
Similar frequent errors you may encounter when trying to connect to the MySQL server:
ERROR 2003: Cannot connect to MySQL server on 'host_name' (111)
ERROR 2002: Cannot connect to local MySQL server through socket '/tmp/mysql.sock' (111)
Errors disabling access to MySQL
In MySQL, an account (Uz) is defined by the user name and the client host from which the user can connect. The username and client host from which a user can connect can also have authentication data (e.g. password).
There may be many reasons for denying access. One of them is related to MySQL accounts, which the server allows client programs to use when connecting. This means that the user name specified in the connection may not have access rights to the database.
In MySQL, it is possible to create accounts that allow users of client programs to connect to the server and access the data. Therefore, in case of an access error, check the permission of the ultrasound to connect to the server through the client program.
You can see the allowed privileges of an account by running the SHOW GRANTS command in the console.
Enter the console (example for Unix, for Windows the console can be found in the start menu):
mysql -u root -p
In the console, enter the command:
> SHOW GRANTS FOR 'tecmint'@'localhost';
You can give privileges to a specific user in the database by IP address using the following commands:
grant all privileges on *.test_db to ‘tecmint’@’192.168.0.100’;
> flush privileges;
Errors of forbidden access can also occur due to problems with MySQL connection (see above).
Loss of MySQL Server connection
You may encounter this error for one of the following reasons:
bad network connection;
the connection waiting time has expired;
BLOB size is larger than max_allowed_packet.
In the first case, make sure you have a stable network connection (especially if you connect remotely).
If you have a problem with the connection timeout (especially when initially connecting MySQL to the server), increase the value of the connect_timeout parameter.
In the case of BLOB size, you should set the higher value for max_allowed_packet in /etc/my.cnf configuration file in [mysqld] or [client] as shown below.
[mysqld]
connect_timeout=100
max_allowed_packet=500M
If the configuration file is not available, this value can be set with the following command.
SET GLOBAL connect_timeout=100;
> SET GLOBAL max_allowed_packet=524288000;
Too many connections
This error means that all available connections are used by client programs. The number of connections (151 by default) is controlled by max_connections system variable. You can fix the problem by increasing the value of the variable in /etc/my.cnf configuration file.
[mysqld]
max_connections=1000
Insufficient memory
If this error occurs, it may mean that MySQL does not have enough memory to store the entire query result.
First, you need to make sure that the query is correct. If it is, you need to perform one of the following actions:
if the MySQL client is used directly, run it with –quick switch to disable cached results;
if you use the MyODBC driver, the user interface (UI) has an extended tab with options. Tick the box “Do not cache result”.
Also can help MySQL Tuner. This is a useful script that connects to a running MySQL server and gives recommendations on how to configure it for higher performance.
$ sudo apt-get install mysqltuner #Debian/Ubuntu
$ sudo yum install mysqltuner #RHEL/CentOS/Ted
$ mysqltuner
To find out the server uptime, run the mysqladmin command.
$ sudo mysqladmin version -p
In addition, you can stop the server, debug MySQL, and restart the service. To display statistics of MySQL processes while other processes are running, open the command line window and enter the following:
$ sudo mysqladmin -i 5 status
Or
$ sudo mysqladmin -i 5 -r status
Conclusion
The most important thing when diagnosing is to understand what exactly caused the error. The following steps will help you do this:
- The first and most important step is to review the MySQL logs stored in /var/log/mysql/. You can use command-line utilities like a tail to read the log files.
- If the MySQL service does not start, check its status with systemctl. Or, use the journalctl command (with -xe flag) in systemd.
- You can also check the system log file (like /var/log/messages) for errors.
- Try using tools such as Mytop, glances, top, ps, or htop to check which program uses the entire CPU resource or locks the machine. They will also help you to detect the lack of memory, disk space, file descriptors or any other important resource.
- If the problem is with a process, you can try to forcefully stop it and then run it (if necessary).
- If you are sure that the problem is on the server-side, you can run the commands: mysqladmin -u root ping or mysqladmin -u root processlist to get an answer from it.
- If the problem is not on the server-side when connecting, check if the client is working properly. Try to get some of its output for troubleshooting.
mysql error 1364 Field doesn’t have a default values
MORE NEWS
PreambleNoSql is not a replacement for SQL databases but is a valid alternative for many situations where standard SQL is not the best approach for...
PreambleMongoDB Conditional operators specify a condition to which the value of the document field shall correspond.Comparison Query Operators $eq...
5 Database management trends impacting database administrationIn the realm of database management systems, moreover half (52%) of your competitors feel...
The data type is defined as the type of data that any column or variable can store in MS SQL Server. What is the data type? When you create any table or...
PreambleMS SQL Server is a client-server architecture. MS SQL Server process starts with the client application sending a query.SQL Server accepts,...
First the basics: what is the master/slave?One database server (“master”) responds and can do anything. A lot of other database servers store copies of all...
PreambleAtom Hopper (based on Apache Abdera) for those who may not know is an open-source project sponsored by Rackspace. Today we will figure out how to...
PreambleMongoDB recently introduced its new aggregation structure. This structure provides a simpler solution for calculating aggregated values rather...
FlexibilityOne of the most advertised features of MongoDB is its flexibility. Flexibility, however, is a double-edged sword. More flexibility means more...
PreambleSQLShell is a cross-platform command-line tool for SQL, similar to psql for PostgreSQL or MySQL command-line tool for MySQL.Why use it?If you...
PreambleWriting an application on top of the framework on top of the driver on top of the database is a bit like a game on the phone: you say “insert...
PreambleOracle Coherence is a distributed cache that is functionally comparable with Memcached. In addition to the basic function of the API cache, it...
PreambleIBM pureXML, a proprietary XML database built on a relational mechanism (designed for puns) that offers both relational ( SQL / XML ) and...
What is PostgreSQL array? In PostgreSQL we can define a column as an array of valid data types. The data type can be built-in, custom or enumerated....
PreambleIf you are a Linux sysadmin or developer, there comes a time when you need to manage an Oracle database that can work in your environment.In this...
PreambleStarting with Microsoft SQL Server 2008, by default, the group of local administrators is no longer added to SQL Server administrators during the...