ubuntu 22.04 安装mysql5.6
Apr 22, 2024
Centos不提供后续维护了, 开始迁移到Ubuntu或者Debian上了, 此文为转载, 方便参考使用.
MySQL Download URL
https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
Open the terminal and follow along:
- Uninstall any existing version of MySQL
1 | sudo rm /var/lib/mysql/ -R |
Delete the MySQL profile
1
sudo rm /etc/mysql/ -R
Automatically uninstall mysql
1
2sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmorDownload version 5.6.46 from MySQL site
1
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
Add mysql user group
1
sudo groupadd mysql
Add mysql (not the current user) to mysql user group
1
sudo useradd -g mysql mysql
Extract it
1 | sudo tar -xvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz |
- Move it to /usr/local
1 | sudo mv mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/ |
Create mysql folder in /usr/local by moving the untarred folder
1
2
3cd /usr/local
sudo mv mysql-5.6.46-linux-glibc2.12-x86_64 mysqlset MySql directory owner and user group
1 | cd mysql |
- Install the required lib package
1
sudo apt-get install libaio1 libncurses5
- Execute mysql installation script
1 | sudo scripts/mysql_install_db --user=mysql |
- Set mysql directory owner from outside the mysql directory
1 | sudo chown -R root . |
- Set data directory owner from inside mysql directory
1 | sudo chown -R mysql data |
- Copy the mysql configuration file
1 | sudo cp support-files/my-default.cnf /etc/my.cnf |
- Start mysql
1
2sudo bin/mysqld_safe --user=mysql &
sudo cp support-files/mysql.server /etc/init.d/mysql.server - Set root user password
1 | sudo bin/mysqladmin -u root password '[your new password]' |
- Add mysql path to the system
1 | sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql |
Reboot!
Start mysql server
1 | sudo /etc/init.d/mysql.server start |
- Stop mysql server
1 | sudo /etc/init.d/mysql.server stop |
Check status of mysql
1
sudo /etc/init.d/mysql.server status
Enable myql on startup
1 | sudo update-rc.d -f mysql.server defaults |
*Disable mysql on startup (Optional)
1 | sudo update-rc.d -f mysql.server remove |
REBOOT!
Now login using below command, start mysql server if it’s not running already
1 | mysql -u root -p |