MySQL database
Determine whether MySQL is installed
sudo systemctl status mysql
If MySQL is installed and running, you will see an output similar to the following:
● - MySQL Community Server Loaded: loaded (/lib/systemd/system/; enabled; vendor preset: enabled) Active: active (running) since ...
If MySQL is not installed, the system will prompt a message similar to the following:
Unit could not be found.
Install MySQL
- Install MySQL Server
sudo apt-get install mysql-server
- Turn on MySQL service
sudo service mysql start
- Confirm whether the MySQL service is on
# Check MySQL service statussudo service mysql status # Or view the MySQL listening port via netstatsudo netstat -tap | grep mysql
- Connect to MySQL database
# Use root user to connect to MySQL databasemysql -u root -p # If you do not set the password, enter directly
- Query user information
USE mysql; # Query user informationSELECT host, user, plugin, authentication_string FROM user;
- If host is localhost, it means that it can only be accessed from the local machine.
- If plugin is not mysql_native_password, the authentication method needs to be modified.
- Modify the root user's password
# Modify the root user's password and set the authentication method to mysql_native_passwordALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Your new password'; # Refresh permissionsFLUSH PRIVILEGES;
- Allow remote access to MySQL
# Modify host from localhost to % to allow remote connection through tools such as NavicatUPDATE SET host='%' WHERE user='root'; # Refresh permissionsFLUSH PRIVILEGES;
- Modify MySQL configuration file
# Edit MySQL configuration filesudo vim /etc/mysql// # Comment or modify the following configuration items:# bind-address = 127.0.0.1 # mysqlx-bind-address = 127.0.0.1
- Restart MySQL service
# Restart the MySQL service to apply configuration changessudo systemctl restart mysql
- Check MySQL listening status
# Check whether MySQL is listening 0.0.0.0:3306sudo netstat -ntlp | grep mysql
Solve the problem that Navicat cannot connect remotely
- Make sure that bind-address and mysqlx-bind-address in the MySQL configuration file are commented or modified to 0.0.0.0.0.
- Restart the MySQL service.
- Check whether the firewall allows MySQL ports (default 3306).
# Check the firewall statussudo ufw status # If you need to open port 3306sudo ufw allow 3306
Through the above steps, you should be able to successfully install MySQL and resolve the issue that Navicat cannot connect remotely. If there are still problems, check the network connection or firewall settings.
Python
Determine whether Python is installed
There are two main versions of Python: Python 2 and Python 3. Usually, Python 3 is installed by default on Ubuntu systems, but since Ubuntu 20.04, Python 2 has been deprecated.
- Check if Python 3 is installed:
python3 --version
If the output is similar to the following, it means that Python 3 is installed:Python 3.8.10
If not installed, an error like the following will be displayed:Command 'python3' not found
- Check if Python 2 is installed:
python --version
If the output is similar to the following, it means that Python 2 is installed:Python 2.7.18
If not installed, an error like the following will be displayed:Command 'python' not found
Install Python 3
sudo apt update sudo apt install python3 python3-pip
- python3 is the main program of Python 3.
- python3-pip is a package management tool for Python that is used to install third-party libraries.
Verify installationAfter the installation is complete, run the following command again to verify:
python3 --version pip3 --version
Nginx
Check if Nginx is installed
Method 1: Use the command line to checkRun the following command to check if Nginx is installed:
nginx -v
If installed, something like the following will be output:nginx: version: 1.26.1
If it is not installed, it will be prompted:nginx: command not found
Method 2: Check Nginx service statusRun the following command to view the Nginx service status:
sudo systemctl status nginx
If Nginx is installed and running, something like the following will be displayed:
- A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/; enabled; vendor preset: enabled) Active: active (running) since Mon 2024-10-07 12:00:00 UTC; 1h 30min ago
If not installed or not running, it will display:
- A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/; enabled; vendor preset: enabled) Active: inactive (dead)
Install from Ubuntu default source
- Update the cache of the package manager:
sudo apt update
- Install Nginx:
sudo apt install nginx
- Start the Nginx service:
sudo systemctl start nginx
- Set up power-on and start:
sudo systemctl enable nginx
- After the installation is complete, you can verify that Nginx is running normally through the following command:
sudo systemctl status nginx
- Visit http://localhost in your browser. If you see the default welcome page of Nginx, it means that the installation is successful.
# The default is port 80. If it is another port, the corresponding port will be opened.# Example: Open port 8000sudo ufw allow 8000/tcp
- Modify configuration
# Modify on server{} nodevim /etc/nginx/sites-enabled/default
Configuration example:
server { listen 8000 ssl; server_name ; # Certificate Configuration ssl_certificate /etc/nginx/cert/.com_cert_chain.pem; ssl_certificate_key /etc/nginx/cert/.com_key.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { proxy_pass http://127.0.0.1:8001; # The forwarded address, that is, the address where Gunicorn runs proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; client_max_body_size 100M; # Client request body size limit # Allow cross-domain access add_header 'Access-Control-Allow-Origin' '*'; # Allowed HTTP methods add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; # Allowed custom request headers add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With'; # Allow cookies (if required) add_header 'Access-Control-Allow-Credentials' 'true'; } location /static { alias /usr/file/images/; expires 30d; client_max_body_size 100M; # Client request body size limit } }
- Check if the configuration is correct
nginx -t
- Reload after modifying the configuration file
service nginx reload
Summarize
This is the article about Ubuntu installation and configuration MySQL, Python, and Nginx. For more information about Ubuntu installation and configuration MySQL, Python, and Nginx, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!