Write a custom directory title here
- Preface
- Install mysql on ubuntu without root permissions
-
- 1. Download and unzip the mysql installation package
- 2. Write my.cnf configuration file
- 3. Install mysql
- 4. Start mysql
- 5. Log in to mysql and change the password
- 6. Enable remote access
- refer to
Foreword
With root privileges, installing mysql is very simple:
# centos yum -y install mysql-community-server #ubuntu sudo apt install mysql-server
However, the laboratory server (ubuntu) usually does not have root permissions
and needs to install mysql through source code. The existing tutorials are basically stuck at the lack of libaio
step. The following are solutions that have been tested and worked by myself.
Install mysql on ubuntu without root permissions
1. Download and unzip the mysql installation package
Directory: /home/project/tools
URL: https://downloads.mysql.com/archives/community/
Select the required mysql version. Here, mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz is selected. Right-click on the Download button and copy the link.
Then run in terminal:
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
Unzip:
tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
Rename the unzipped folder to mysql:
mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
2. Write my.cnf configuration file
Enter the mysql directory, create and write the my.cnf file:
cd mysql vim my.cnf
Insert the following:
[client] port=3306 socket=/home/project/tools/mysql/mysql.sock [mysqld] port=3306 basedir=/home/project/tools/mysql datadir=/home/project/tools/mysql/data pid-file=/home/project/tools/mysql/mysql.pid socket=/home/project/tools/mysql/mysql.sock log_error=/home/project/tools/mysql/error.log server-id=100 # Set case insensitivity lower_case_table_names=1
3. Install mysql
Enter the bin directory:
cd bin
Run and modify the mysqld file:
./mysqld \ --defaults-file=/home/oper/mysql/my.cnf \ --initialize \ --user=mysql \
An error may be reported at this time: ./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
That is, libaio is missing, which is easy to solve when you have root permissions. Just execute sudo apt-get install libaio1
. If you don’t have root permissions, you need to install and configure it manually.
(1) Download libaio installation package
Run the following command in the mysql directory to download libaio-0.3.109-13.el7.x86_64.rpm
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libaio-0.3.109-13.el7.x86_64.rpm
(2) Unzip the libaio installation package
Non-root users can only use rpm2cpio
to decompress:
rpm2cpio libaio-0.3.109-13.el7.x86_64.rpm |cpio -idvm
(3) Modify soft links
Enter the lib64 directory to check the connection status:
cd lib64 ll
It can be seen that the soft link of ibaio.so.1 points to /lib64/libaio.so.1.0.1 by default and needs to be modified to point to /home/project/tools/mysql/lib64/libaio.so.1.0.1:
ln -snf /home/project/tools/mysql/lib64/libaio.so.1.0.1 libaio.so.1
ll again to view soft connections:
(4) Modify environment configuration
Enter the user’s home directory and create a new configuration file .bash_profile
:
cd ~ vim .bash_profile
Insert the following content in the configuration file (add LD_LIBRARY_PATH, add a new path to mysql/bin):
# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/project/tools/mysql/bin export LD_LIBRARY_PATH=$HOME/project/tools/mysql/lib64 export PATH=$PATH
Execute configuration file:
source .bash_profile
Enter env in the terminal to view the current environment variables and find that LD_LIBRARY_PATH and PATH have been modified (PATH has added the path after the last colon):
(5) Try installing mysql again
cd project/tools/mysql/bin ./mysqld \ --defaults-file=/home/oper/mysql/my.cnf \ --initialize \ --user=mysql \
No results are returned and no error is reported. At this time, mysql is successfully installed.
4. Start mysql
Execute the following commands in sequence, no error is reported:
./mysqld_safe --defaults-file=/home/project/tools/mysql/my.cnf --user=mysql & amp;
Start a new terminal and it can listen to port 3306, which means the startup is successful:
cd /home/project/tools/mysql netstat -tln | grep 3306
5. Log in to mysql and change the password
Check the initial password. The initial password is in the error.log file in the mysql directory. The password here is lwen8bwZ8j,c:
cat error.log | grep root@localhost
Log in and enter initial password:
mysql -u root -p -S /home/project/tools/mysql/mysql.sock
After successful login, enter the following command to change the password:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456'); --Set the login password to 123456 flush privileges;
6. Enable remote access
When using third-party tools to connect to the MySQL database, you need to enable MySQL’s remote access restrictions in advance.
Switch to the mysql database in the mysql interface to view user authentication information:
use mysql select User,authentication_string,Host from user;
It can be seen that the access permissions of localhost here.
To allow hosts with other addresses to access mysql, you need to modify the permissions. The password here is 123456
. Actually, according to your choice, %
represents all hosts, or it can be specific to the IP address:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456'; --Allow other hosts to access flush privileges;
Check the table again and you will find that there are more users, indicating that remote access has been successfully enabled. You can use tools to connect remotely:
select User,authentication_string,Host from user
At this point, mysql has been installed!
Reference
- Linux ordinary users install and configure mysql (non-root permissions)
- Tutorial on installing sqlplus client for non-root users in centos 7 or ubuntu18.04 without oracle database environment
- Under Linux, non-root users install and configure mysql