• Home
  • DBA Scripts
    • Oracle Scripts
    • SQL Server Scripts
  • Knowledge Base
    • Oracle Database
    • MS SQL Server
    • MongoDB
    • MariaDB
  • Troubleshoot
    • Oracle Database Issues
    • SQL Server Issues
  • Interview Questions
    • AWS Interview Questions
    • Oracle DBA Interview Questions
    • SQL Server Interview Questions
  • Courses
    • Oracle Database
    • Oracle DBA L1
    • Oracle DBA L2
    • Oracle DBA L3
  • Home
  • DBA Scripts
    • Oracle Scripts
    • SQL Server Scripts
  • Knowledge Base
    • Oracle Database
    • MS SQL Server
    • MongoDB
    • MariaDB
  • Troubleshoot
    • Oracle Database Issues
    • SQL Server Issues
  • Interview Questions
    • AWS Interview Questions
    • Oracle DBA Interview Questions
    • SQL Server Interview Questions
  • Courses
    • Oracle Database
    • Oracle DBA L1
    • Oracle DBA L2
    • Oracle DBA L3
home/Knowledge Base/MariaDB/MariaDB – Connection
Popular Search:Oracle, SQL Server, MongoDB

MariaDB – Connection

65 views 0 June 1, 2020 admin

One way to establish a connection with MariaDB consists of using the mysql binary at the command prompt.

MYSQL Binary

Review an example given below.

[root@host]# mysql -u root -p

Enter password:******

The code given above connects to MariaDB and provides a command prompt for executing SQL commands. After entering the code, a welcome message should appear indicating a successful connection, with the version number displayed.

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 122323232

Server version: 5.5.40-MariaDB-log

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

The example uses root access, but any user with privileges can of course access the MariaDB prompt and perform operations.

Disconnect from MariaDB through the exit command as follows:

mysql> exit

PHP Connection Script

Another way to connect to and disconnect from MariaDB consists of employing a PHP script. PHP provides the mysql_connect() function for opening a database connection. It uses five optional parameters, and returns a MariaDB link identifier after a successful connection, or a false on unsuccessful connection. It also provides the mysql_close() function for closing database connections, which uses a single parameter.

Syntax

Review the following PHP connection script syntax:

connection mysql_connect(server,user,passwd,new_link,client_flag);

The description of the parameters is given below:
Parameter Description
server This optional parameter specifies the host name running the database server. Its default value is “localhost:.3036.”
user This optional parameter specifies the username accessing the database. Its default value is the owner of the server.
passwd This optional parameter specifies the user’s password. Its default value is blank.
 

new_link

This optional parameter specifies that on a second call to mysql_connect() with identical arguments, rather than a new connection, the identifier of the current connection will be returned.
 

 

 

client flags

This optional parameter uses a combination of the following constant values-

·        MYSQL_CLIENT_SSL – It uses ssl encryption.

·        MYSQL_CLIENT_COMPRESS – It uses compression protocol.

·        MYSQL_CLIENT_IGNORE_SPACE – It permits space after function names.

·        MYSQL_CLIENT_INTERACTIVE – It permits interactive timeout seconds of inactivity prior to closing the connection.

Review the PHP disconnection script syntax given below:

bool mysql_close (resource $link_identifier );

If you omit the resource, the most recent opened resource will close. It returns a value of true on a successful close, or false.
Try the following example code to connect with a MariaDB server:

<html>
<head>
<title>Connect to MariaDB Server</title>
</head>
<body>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'guest1';
$dbpass = 'guest1a';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($conn);
?>
</body>
</html>

On successful connection, you will see the following output:

mysql> Connected successfully

 

Was this helpful?

Yes  No
Related Articles
  • MariaDB – Where Clause
  • MariaDB – Select Query
  • MariaDB – Insert Query
  • MariaDB – Drop Tables
  • MariaDB – Create Tables
  • MariaDB – Data Types
Leave A Comment Cancel reply

MariaDB
  • MariaDB – Connection
  • MariaDB – Where Clause
  • MariaDB – Select Query
  • MariaDB – Insert Query
  • MariaDB – Drop Tables
  • MariaDB – Create Tables
View All 14  
Popular Articles
  • Upgrade Oracle Database from 11.2.0.3 to 12.1.0.2
  • Upgrading MariaDB on Windows
  • Oracle DBA Basic Interview Questions Part A
  • Purging Oracle Sysaux Tablespace
  • Client – Server Architecture
KB Categories
  • Oracle Database
    • Oracle RAC
    • Oracle ASM
    • Oracle GoldenGate
    • Oracle Tuning
    • Oracle 11g Database
    • Oracle Database Upgrade
    • Oracle 12c Database
    • ALL KB Oracle
    • Oracle 18c Database
    • Oracle Standby Database
  • MongoDB
  • MS SQL Server
  • MySQL
  • Interview Questions
    • AWS Interview Questions
    • Oracle DBA Interview Questions
    • SQL Server Interview Questions
  • MariaDB
Database Organization

Database Organization (DB ORG) is knowledge base for DBA to learn and execute the fundamental of different databases under one website. DB ORG is a non-profit initiative. ORACLE, MS SQL Server, MongoDB, MariaDB, Couchbase

Join Our Community
  • KnowledgeBase
  • Documentation
  • Troubleshoot
  • FAQ
Information Links
  • About DBOrg
  • Licenses
  • Terms
  • Privacy Policy
Contact Us
    DB ORG - Database Administration,
    Knowledge Base for DBA
    Mail: support@databaseorg.com
    WhatsApp: (+91) 9306440957
    Monday to Friday: EST - 11:30 AM to 06:30 PM (IST - 9:00 PM to 4:00 AM)
  • © 2023 Database Organization - DB ORG. All Rights Reserved.

Popular Search:Oracle, SQL Server, MongoDB

WhatsApp DB Org