Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Setting Up MySQL Without Root Access

DZone's Guide to

Setting Up MySQL Without Root Access

This article covers how to install and run MySQL as a non-root user in Linux.

· Database Zone ·
Free Resource

Compliant Database DevOps and the role of DevSecOps DevOps is becoming the new normal in application development, and DevSecOps is now entering the picture. By balancing the desire to release code faster with the need for the same code to be secure, it addresses increasing demands for data privacy. But what about the database? How can databases be included in both DevOps and DevSecOps? What additional measures should be considered to achieve truly compliant database DevOps? This whitepaper provides a valuable insight. Get the whitepaper

Many times, we have access to Linux boxes, but do not have access to root login or any sudo privileges. Hence this approach.

We are using the MySQL Community Edition 5.7.13

Setup

We untarred the downloaded mySQL into a src folder. For example : /users/mysql

We will refer to this as $MYSQL_HOME. Please make sure that this is set in the environments:

1. Create $MYSQL_HOME/data directory.

2. Create$MYSQL_HOME/log directory.

Install

Change to  $MYSQL_HOME and create two files — my.ini and my.cnf
my.cnf has the following content:

[mysqld]
user=<userName>

my.ini has the following content:

export BASE_DIR=$MYSQL_HOME
export DATADIR=$BASE_DIR/data

Make sure that the entries are part of your environment (makes it easier to start the daemon).

The following command initializes the mySQL data base and creates the initial set of tables:

./mysqld 
--user=<userName> 
--datadir=$DATADIR 
--basedir=$MYSQL_HOME
--log-error=$MYSQL_HOME/log/mysql.err 
--pid-file=$MYSQL_HOME/mysql.pid 
--socket=$MYSQL_HOME/socket 
--port=3306 
--initialize

The log file will be stored in$MYSQL_HOME/log/mysql.err After the initial install, open the file to check the root password. You should see this line:

A temporary password is generated for root@localhost: XfU(%qmrk7)y

Take a note of this and then change it.

MySQL Daemon

startup.sh

In the $MYSQL_HOME/bin create a startup.sh file. the content of the file is as below:

export BASE=$MYSQL_HOME
$BASE/bin/mysqld 
--user=<userName>
--datadir=$BASE/data 
--basedir=$BASE 
--log-error=$BASE/log/mysql.err
--pid-file=$BASE/mysql.pid 
--socket=$BASE/socket 
--port=3306

Set the executable bit to 755 by executing chmod.

shutdown.sh

The file to shutdown should be placed in /srv/tempo/pgms/mysql/bin. The content is as below: The content should be executable:

export BASE=/srv/tempo/pgms/mysql
$BASE/bin/mysqladmin 
--socket=$BASE/socket shutdown -u root -p

This file should also have the executable bit set.

Starting MySQL

Navigate to $MYSQL_HOME and execute the ./startup.sh.

Stopping MySQL

Navigate to $MYSQL_HOME and execute the ./shutdown.sh.

You will be prompted to enter your password to proceed.

Note: You need a root user account to add this to init.d

Happy working on MySQL as non-root:-)


Note : This article is also published on my personal blog.

Compliant Database DevOps and the role of DevSecOps DevOps is becoming the new normal in application development, and DevSecOps is now entering the picture. By balancing the desire to release code faster with the need for the same code to be secure, it addresses increasing demands for data privacy. But what about the database? How can databases be included in both DevOps and DevSecOps? What additional measures should be considered to achieve truly compliant database DevOps? This whitepaper provides a valuable insight. Get the whitepaper

Topics:
mysql 5.7 ,mysql administration ,linux ,database ,database administration

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}