How to Install MySQL in the Linux / Ubuntu operating system.
This installation is based on the scnerio where we are going to use tar file to install into non-default location on the ubuntu server.
**All the below steps are performed as the ROOT user
1. Install the necessary packages
apt-get update apt-get install libncurses5-dev libncursesw5-dev libaio1 libncurses5
2. Create mysql user:
groupadd mysql useradd -r -g mysql -s /bin/false mysql
3. Create necessary directories as below using mkdir command.
base directory => mkdir -p /u01/mysql/base data directory => mkdir -p /u01/mysql/data log directory => mkdir -p /u01/mysql/logs
4. Download MySQL version 8.0.32 using the below wget command.
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz untar the file in base directory /u01/mysql/base tar -xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
– copy content of mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz to one directory back in base directory.
– Change owner ship of the directories created in Step 3 to mysql
chown -R mysql:mysql /u01/mysql
5. Create confirgurtaion file my.cnf under /etc
vi /etc/my.cnf
[mysqld] basedir=/u01/mysql/base datadir=/u01/mysql/data log_error=/u01/mysql/logs/error.log port=3306 socket=/u01/mysql/data/mysql.sock
– Change ownership to mysql
chown mysql:mysql /etc/my.cnf
6. Initialize the MySQL
cd /u01/mysql/base/bin ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
Start the MySQL Services:
cd /u01/mysql/base/bin ./mysqld --defaults-file=/etc/my.cnf --user=mysql &
=> Create soft link to socket file in case not default location:
ln -s /u01/mysql/data/mysql.sock /tmp/mysql.sock
7. Login into the MySQL using the temporary password generated in below error log file and change the password.
log_error=/u01/mysql/logs/error.log
cd /u01/mysql/base/bin ./mysql -uroot -p alter user root@localhost identified by 'root'; show databases;