DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Is 2025 the year of API-first development and democratization? Take our annual survey and tell us how you implement APIs across your org.

Explore common security challenges that data engineering teams face. Leverage that to build secure data pipelines with Apache Airflow.

GenAI: See the trends surrounding GenAI models, algorithms, implementation, its impacts on code generation, and development as a whole.

80% of respondents actively use Docker. See what other software platforms and tools are most commonly used by developers.

Related

  • Codify Your Cloud and Kubernetes With Crossplane and IaC
  • Troubleshooting Connection Issues When Connecting to MySQL Server
  • Logical Reasoning in Network Problems
  • In-Depth Analysis of MySQL 8.0 Performance Degradation

Trending

  • A Systematic Approach for Java Software Upgrades
  • Supercharging Pytest: Integration With External Tools
  • Jakarta NoSQL 1.0: A Way To Bring Java and NoSQL Together
  • A Pulse on Generative AI Today: Navigating the Landscape of Innovation and Challenges
  1. DZone
  2. Data Engineering
  3. Databases
  4. Setting Up MySQL Without Root Access

Setting Up MySQL Without Root Access

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

By 
Vivek Raman user avatar
Vivek Raman
·
Jun. 24, 16 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
22.8K Views

Join the DZone community and get the full member experience.

Join For Free

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.

MySQL

Published at DZone with permission of Vivek Raman. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Codify Your Cloud and Kubernetes With Crossplane and IaC
  • Troubleshooting Connection Issues When Connecting to MySQL Server
  • Logical Reasoning in Network Problems
  • In-Depth Analysis of MySQL 8.0 Performance Degradation

Partner Resources


Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!