Skip to main content

Installing and Using JSON on MySQL 5.7

As we know that MySQL come up with JSON datatype equivalent(but not completely) to MongoDB's Document Store Database.

In this post, we are going to see how to Install and Use MySQL's new JSON datatype.


Installing MySQL - JSON Plugin:

1. In order to use JSON datatype in MySQL, we need to have MySQL 5.7.12 or higher versions.
  • Download the latest version of MySQL 5.7.12 or higher from here.
2. Installing the X Plugin
  • A non-root user will have access to install the X Plugin on MySQL database, since he have to perform INSERT operations on the database.
  • There are 3 types of Plugin installations available. 
  • Using MySQL installer for Windows:
    • Launch MySQL Installer for Windows.
    • Click the Reconfigure option. Use Next and Back to configure for following actions:
      • In Accounts and Roles, confirm the current root account password
      • In Plugin and Extensions, check mark the Enable X Protocol/MySQL as a Document Store check box.
      • In Apply Server Configuration, click Execute.
      • Click Finish to close the installer.
  • Using MySQL Client Program for Centos/Redhat/Linux flavours:
    • Open terminal window
    • Login to MySQL with root credentials.
    • Issue the following statement to install X plugin
    • mysql> INSTALL PLUGIN mysqlx SONAME 'mysqlx.so';
Note: Replace mysqlx.so with mysqlx.dll for windows

3. Verifying that the X Plugin has been installed.
  • When we installed the plugin correctly, without any issues it will show up in the plugins list.
  • Login to MySQL and issue below statement
  • mysql -u user -p
    
    mysql> show plugins;
    ---------------------------------------------------------------------------------------
    mysqlx                      | ACTIVE   | DAEMON             | mysqlx.so          | GPL 
    ---------------------------------------------------------------------------------------
  • You will get ACTIVE message as above.
4. MySQL Shell (Optional)
  • MySQL has released MySQL Shell as an interactive client especially designed for the JSON.
  • To install MySQL Shell on Windows and Linux.
    • Windows:
      • Download the Windows (x86, 64-bit), MSI Installer package from here
      • When prompted, click Run
      • And click Next.
    • Linux:
    • $ yum install mysql-shell -y
For more information about usage of MySQL Shell click here

Etablishing a session with MySQL Shell:
mysqlsh --uri user@localhost
Logging to MySQL JSON with specific database name:
mysqlsh username@localhost/databasename

Example:

mysqlsh root@localhost/test_json_db
Creating a session to 'root@localhost/test_json_db'
Enter Password: *********
After the successful login you will now prompted to MySQL Shell like below:
mysql-js>

Comments

Popular posts from this blog

Warning: Using a password on the command line interface can be insecure

We usually use MySQL login information on shell scripts to load some data into database or to fetch some monitoring information. To login to the database will write login information on Shell Scripts as below #!/bin/sh username = someusername password = somepassword $ mysql -u$username -p$password -A -v -S By doing that so, we will hit a warning in stdout saying: Warning: Using a password on the command line interface can be insecure To avoid the warning in shell script, we need to so some workaround like below: 1. Create a hidden file configuration file > touch /tmp/.mysqllogin.cnf 2. Enter your database credential information on the hidden file: > vi /tmp/.mysqllogin.cnf [client] user=someusername password=somepassword 3. Save the file and try to login to mysql using  --defaults-extra-file  keyword like $ mysql --defaults-extra-file=/tmp/.mysqllogin.cnf -A -v By using this workaround you can avoid the warning.

Unable to open the log file (mysqld)

While starting the server you may find the below errors sometimes, it's because of unintentionally deleting the MySQL Binary Log files. When starting mysql if the server unable to find the mysql-bin-log files then below errors will arise. 170418 12:15:19 InnoDB: 5.5.30 started; log sequence number 32347593422 /usr/sbin/mysqld: File './mysql-bin.000023' not found (Errcode: 2) 170418 12:15:19 [ERROR] Failed to open log (file './mysql-bin.000023', errno 2) 170418 12:15:19 [ERROR] Could not open log file 170418 12:15:19 [ERROR] Can't init tc log 170418 12:15:19 [ERROR] Aborting 170418 12:15:19 InnoDB: Starting shutdown... 170418 12:15:20 InnoDB: Shutdown completed; log sequence number 32347593422 170418 12:15:20 [Note] /usr/sbin/mysqld: Shutdown complete Do we have a solution to get rid of this and start MySQL again? Well, we have two types of workarounds to start MySQL again. 1. Deleting the missed files in binlog .index  file 2. Disabling the binlog log

Installing,Starting,Stopping PostgreSQL Server on Linux OS

In this post, we will see how to Install and Run PostgreSQL on Linux machines. There are three ways to installation procedures to download the software. 1. Binary Installation 2. Yum Installation 3. RPM Installation In this post, will see how to install PostgreSQL using Binary installation. 1. Download the binaries from the official website. $ wget https://get.enterprisedb.com/postgresql/postgresql-9.6.2-4-linux-x64-binaries.tar.gz 2. Untar the downloaded binaries. $ tar -xvzf postgresql-9.6.2-4-linux-x64-binaries.tar.gz 3. Create appropriate data directories and permissions with root user to run PostgreSQL Server. # mkdir -p /var/lib/pgsql/data # chown -R psql /var/lib/pgsql/data # su psql 4. Now change the directory path to the downloaded software path $ cd /home/psql/softwares/pgsql 5. Initialize the data directories required for PostgreSQL to run, there are two ways to initialize the directories. $ initdb -D /usr/local/pgsql/data Alternatively, we can also