How to Connect MySQL in Linux (2024)

How to Connect MySQL in Linux

MySQL & mysqldump employ parameters from the command line to tailor their connection to the MySQL server. Please refer to Section 4.2.5, “Connecting to the Server Using URI-Like Strings or Key-Value Pairs,” for details about how to connect clients like MySQL Shell using URI-like connection string or key-value pairs. If you’re having trouble establishing a connection to MySQL, check out Section 6.2.22 for further details.


Connection parameters, like the hostname where a server runs & your MySQL account’s password and username, are required for a client software to establish a connection with the MySQL server. If you need to change the preset value for a connection parameter, you can do so by specifying a new value for that parameter via the command line or a setting file.

If you run the client program with the –password or -p option but do not supply a password, it will display a prompt asking for the password. (In these situations, mydb is not considered a password as it follows a space and is not followed by another password choice.)

MySQL’s password prompting library routine may impose an eight-character cap on passwords on certain platforms. This restriction does not exist in MySQL but rather in the system library. MySQL’s internals do not impose a maximum length on passwords. On impacted systems, you can avoid the restriction by setting the password in a possibility file (for more information, see Section, “Using Option Files”). Alternatively, you might try changing your MySQL password to something with fewer than eight characters, but keep in mind that such passwords are typically less secure.

Set Up a MySQL Database on Linux

Installing a MySQL server as well as ODBC driver, and then setting up Media Server to utilize the driver for connecting to the database, are prerequisites for using MySQL with Media Server.

For candidates who want’s to advance their Career in Operating System & Administration, Linux  Training Course is the best option.

So, here are detailed steps necessary to install MySQL on CentOS 6.

Installing MySQL for Media Server under Linux:

1. Set up a server running MySQL. (Do check that the mysql command-line program is part of the package.) Please see the MySQL manual at for further information.

2. Set up the database server so that Media Server can access it.

  • Launch the MySQL server’s configuration file (often called my.ini)
  • Enter the configuration parameter max_allowed_packet=1073741824 to enable Media Server to transmit huge amounts of binary data (images) to the databases. 
  • Remove the configuration file after saving changes.

3. To include the MySQL bin directory in your PATH variable, type in the following command:

(export PATH=$PATH:binDirectoryPath)

Please take note that this action prepares the terminal for using the mysql command to launch the mysql command-line tool. 

4. To launch mysql, you have to enter the full path to the mysql.exe file in the terminal unless you have already set the PATH environment variable to include the directory.

5. Launch the mysql steps command prompt. Type the following into the terminal:

  • To make a new database, you can use the CREATE DATABASE statement. Please use the following parameters for your database.
Database nameAny names
Character setShould be Unicode–either UCS2/UTF8
CollationChoose any which is consistent with proper encoding.
  • To use the Media Server database, use the my.sql script located in the server’s installation folder. This script creates the database structure necessary for Media Server to function.
  • Put an end to the mysql command prompt session. Type the following into the terminal:

(-u userName -p -v -D “source path/my.sql” -e “databaseName” -e “where,”)

userNameis MySQL username.
databaseNameis the database name you made in the 3rd step.
pathis this script file path.

Non-interactive script execution via the terminal prevents script from continuing execution after an error.

6. Provide access to the MySQL server for users that Media Server will use in order to connect.  Essential rights include:

DatabaseCreate Temporary Table
All tablesInsert, Select, Update, Delete
All functions & stored proceduresExecution

If security doesn’t pose an issue, give full access.

  • To launch the mysql CLI:


Execute the GRANT procedures:

* TO username 




DELETE ON databasename

*TO username

  • EXECUTE RIGHTS GRANTED ON databaseName.username * TO; where,
databaseNameis the name of the particular database you developed in the 2nd step.
userNameis the username which Media Server can not connect.

Close the mysql command-line tool:

7. Upgrade to unixODBC driver management 2.2.14. In the terminal, do sudo yum install unixODBC when you have access to the necessary Yum repository

8. Mount the MySQL device driver. In the terminal, type sudo yum install mysql-connector-odbc if you are connected to the appropriate Yum repository.

9. It’s time to set up the data source:

  • It is best to use an editor for text to open the odbc.ini file. The /etc directory is the typical location for this file.
  • Fill in a square parentheses with the name of the data source. This name may be whatever string you like. Case in point:
  • Please modify the following settings under “data source name:
DriverThe driver to utilise.
ServerThe hostname or IP address of the particular server that database server has been installed on.
PortThe port to utilise to convey with this database server.
UserThis username is attached to the database server.
PasswordThe particular password for an user account which connects to those database servers.
DatabaseThe database name which you developed in the 3rd step.

For example:







  • NOTE:
    In addition to the parameters checked with Media Server, you may configure extra options in this file.
  • Don’t forget to save your work and exit the file.

10. Configure this ODBC driver

  • Open the odbcinst.ini file with a text editor. This file is usually stored in the /etc directory.
  • If not already present, add the database server name in square brackets. For example: [MySQL]
  • Set the following parameters.
DescriptionA description of the driver instance.
Driver64The location of the MySQL driver library file.
Setup64The location of the driver installer file.
FileUsageSet this parameter to 1.

For example:

Description=ODBC for MySQL



NOTE: You can change other settings in this file, but Media Server has not been used to test them.

Save the file and close it.

11. Now, you can set up Media Server so that it can join to the database.


Using JDBC (Java Database Connectivity), we may establish a connection from Java code to our MySQL database. To simply execute our query, assertion, and get data from the database, we can use JDBC, one of the standard APIs for database connectivity. You must first manually populate a list in your MySQL database with some data before running the aforementioned code.

0 0 votes
Article Rating
Was this article helpful?
Notify of

Inline Feedbacks
View all comments
Scroll to Top