Change MySQL port number for security purpose

CK CK 3788 
Created at
Updated at  
816 0 0

The default port that MySQL database server is running under Linux and Unix is 3306/TCP. In order to change the default MySQL/MariaDB database port in Linux, open MySQL server configuration file for editing by issuing the below command.

# vi /etc/my.cnf.d/server.cnf                   [On CentOS/RHEL]
# vi /etc/mysql/mariadb.conf.d/50-server.cnf    [On Debian/Ubuntu]

Search for the line stat starts with [mysqld] and place the following port directive under [mysqld] statement, as shown in the below file excerpts. Replace the port variable accordingly

[mysqld]
port = 12345

After you’ve added the new MySQL/MariaDB port, save and close the configuration file.

 

If you use SELinux, you should install the following package under CentOS 7 in order to apply the required SELinux rules to allow the database to bind on the new port.

# yum install policycoreutils-python

Next, add the below SELinux rule to bind MySQL socket on the new port and restart the database daemon to apply changes, by issuing the following commands. Again, replace MySQL port variable to match your own port number.

On CentOS/RHEL

# semanage port -a -t mysqld_port_t -p tcp 12345
# systemctl restart mariadb

On Debian/Ubuntu

# systemctl restart mysql


In order to verify if the port configuration for MySQL/MariaDB database server has been successfully applied, issue netstat or ss command and filter the results via grep command in order to easily identify the new MySQL port.

# ss -tlpn | grep mysql
# netstat -tlpn | grep mysql 
Tags CentOS7 MySQL MySQL Port Facebook X
Comments 0
Similar posts
  1. Check network port is open or not on CentOS 7
    1,189
  2. chmod by type (directory and file permission)
    734
  3. CentOS warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory on CentOS 7
    1,073
  4. Using MySQL in Node.js
    481
  5. Rust code example to access MySQL
    1,098
  6. The Ultimate Data Engineering Roadmap
    1,073
  7. How to install python 3.9 alongside python 3.8 on CentOS 7?
    711
  8. How do I create a user account in read-only mode at MySQL?
    3,321
  9. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    288
  10. Stateful Databases: A Deep Dive with Cassandra & TiDB
    189
  11. How to set AUTO_INCREMENT ID in mySQL ?
    607
  1. Why SPF and DKIM Are Essential for Linux Email Servers?
    36
  2. Upgrading to GCC 4.9.4 in CentOS 7 requires installing a newer version manually
    583
  3. Force no caching in Apache by modifying the .htaccess file using appropriate headers
    2,676
  4. Beyond your conventional memory size with swap file instead of a partition
    1,143
  5. Gmail requires all senders to authenticate with either SPF or DKIM.
    681
  6. Bash script to install postfix and sasl for sending email
    1,197
  7. Guide for tmux shortcuts - split current pane, toggle pane
    1,304
  8. Tistory remote blogging example based in CLI & PHP
    2,725
  9. Generate Let’s Encrypt Wildcard SSL Certificate
    626
  10. Preventing Unauthorized Image Crawling by Bots: A Clever Discovery and How to Address It
    1,728
  11. Network diagnostic tool for IPv4/IPv6 - traceroute/traceroute6
    1,919
  12. Set up an SMTP server on CentOS 7
    727
  13. How to mount windows shared folder on Centos 6.8 - mount error 12 = Cannot allocate memory to the mount.cifs(8)
    913
  14. Configuring IP Address on Centos 6.7
    791
  15. Adding new cron job for automated processing on every 10 minutes on Centos 6.7
    1,332
  16. Set timezone and time on Centos 6.7
    541
  17. How to optimize MySQL automatically in CentOS Linux
    1,008
  18. File conversion to UTF in Schell Script
    1,024
  19. Server status checking by Shell Script
    1,516
  20. How can I increase MySQL max connections?
    461
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    42
  2. How do I create animated background for Google Meet?
    21,036
  3. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    252
  4. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  5. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  6. Array of arguments passed to script in PHP
    90
  7. Invalid Auction Storms in Ad Tech
    98
  8. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  9. The Two Clocks of Ad Server Architecture
    70
  10. Frequency Cap Architecture Overview
    515
  11. Collecting Proof-of-Play from 100,000 Screens
    146
  12. What is RedisVL?
    109
  13. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    232
  14. TPU & GPU Cluster Management Tools
    245
  15. The Concept of Scaffolding in AI Agents
    234
  16. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  17. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    259
  18. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  19. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  20. Machine Learning: Training vs. Ranking
    222
  21. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  22. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  23. Designing a Data Curation System Around a Vector Database
    221
  24. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  25. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  26. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    196
  27. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    219
  28. Understanding Data Lineage
    263
  29. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    167
  30. GPU & LLM Cluster Infrastructure & Task Scheduling Architecture
    245