DeveloperBreeze

By default, MySQL stores all its data in /var/lib/mysql. This tutorial explains how to safely move the MySQL data directory to a new location (e.g., another disk or partition) on Ubuntu 25.04.

🔧 Step 1: Stop the MySQL Service

Before making any changes, stop the MySQL service:

sudo systemctl stop mysql

🔧 Step 2: Move the Existing Data Directory

Choose your new location, for example /mnt/data/mysql, and move the current data:

sudo mv /var/lib/mysql /mnt/data/mysql

> This moves all database files including system schemas like mysql and performance_schema.


🔧 Step 3: Set Correct Permissions

Ensure MySQL can access the new directory:

sudo chown -R mysql:mysql /mnt/data/mysql

🔧 Step 4: Update MySQL Configuration

Edit the MySQL configuration file:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Find the line:

datadir = /var/lib/mysql

Change it to:

datadir = /mnt/data/mysql

Save and exit.


🔧 Step 5: (If AppArmor is Enabled) Add Access Rules

AppArmor may block MySQL from accessing the new path.

Edit AppArmor profile for MySQL:

sudo nano /etc/apparmor.d/usr.sbin.mysqld

Add these lines before the closing }:

/mnt/data/mysql/ r,
/mnt/data/mysql/** rwk,

Then reload AppArmor:

sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld

🔧 Step 6: Fix MySQL Socket Directory (Optional)

If needed, recreate the MySQL socket directory:

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

🔧 Step 7: Restart MySQL

sudo systemctl start mysql

✅ Step 8: Verify the New Data Directory

Check that MySQL is using the new path:

mysql -u root -p -e "SHOW VARIABLES LIKE 'datadir';"

You should see:

+---------------+------------------+
| Variable_name | Value            |
+---------------+------------------+
| datadir       | /mnt/data/mysql/ |
+---------------+------------------+

Continue Reading

Discover more amazing content handpicked just for you

Tutorial

How to Stop SSH From Timing Out

ClientAliveInterval 60
ClientAliveCountMax 3

This makes the server send a keep-alive packet every 60 seconds, allowing up to 3 missed replies before disconnecting.

Aug 21, 2025
Read More
Tutorial

How to Translate URLs in React (2025 Guide)

{
  "routes": {
    "home": "home",
    "about": "about-us"
  },
  "title": "Welcome to our site!"
}

Sample fr.json:

May 04, 2025
Read More
Tutorial

Globalization in React (2025 Trends & Best Practices)

  • 🇪🇺 GDPR requires local-language privacy policies
  • 🇨🇳 China's Cybersecurity Law needs local hosting + Mandarin support
  • 🇸🇦 Saudi localization laws mandate Arabic for all government services

Your React app must support legal localization where applicable.

May 04, 2025
Read More
Tutorial

Implementing Internationalization (i18n) in a Large React Application (2025 Guide)

  • ✅ Add lang attribute dynamically to <html lang="...">
  • ✅ Use language subpaths (e.g., /en/home, /fr/home) for SEO indexing
  • ✅ Translate all visible UI, not just text
  • ✅ Localize URLs and metadata (title, description)
  • ✅ Use hreflang tags in SSR setups (Next.js, Remix)

Use localStorage via i18next-browser-languagedetector:

May 04, 2025
Read More
Tutorial

Building Micro-Frontends with Webpack Module Federation (2025 Guide)

We’ll build two apps:

/app-shell         (React)
  ├── webpack.config.js
  ├── src/
      └── bootstrap.js

/analytics-app     (Vue)
  ├── webpack.config.js
  ├── src/
      └── main.js

May 04, 2025
Read More
Tutorial

State Management Beyond Redux: Using Zustand for Scalable React Apps

import create from 'zustand';
import { persist } from 'zustand/middleware';

const useStore = create(persist(
  (set) => ({
    count: 0,
    increase: () => set((state) => ({ count: state.count + 1 })),
  }),
  {
    name: 'counter-storage',
  }
));

Zustand allows you to select specific parts of the state to prevent unnecessary re-renders:

May 03, 2025
Read More
Tutorial

Mastering React Rendering Performance with Memoization and Context

By wrapping increment and decrement with useCallback, their references remain stable across renders, preventing unnecessary re-renders in child components that receive these functions as props.([GeeksforGeeks][2])

For components that perform heavy computations, useMemo can cache the result of a calculation, recomputing it only when its dependencies change.([Content That Scales][5])

May 03, 2025
Read More
Tutorial

✅ How to Disable MySQL Password Validation on Ubuntu 25.04

This should now work without any errors.

If you want to bring back strong password policies:

May 01, 2025
Read More
Tutorial

How to Install PHP, MySQL, and phpMyAdmin on Ubuntu 25.04 (LAMP Stack Setup Guide)

If you're using Apache and want to set up a virtual host for your Laravel application:

   sudo nano /etc/apache2/sites-available/your_domain.conf

May 01, 2025
Read More
Tutorial

How to Fix NVIDIA Driver Issues on Ubuntu (Dell Vostro 3521)

These will run on the NVIDIA GPU only, saving power when not needed.

  • Use prime-select query to check current mode (intel, nvidia, or on-demand).
  • Switch modes:

Apr 14, 2025
Read More
Tutorial

Avoiding Memory Leaks in C++ Without Smart Pointers

In this tutorial, you'll learn:

  • How memory leaks happen.
  • How to structure your code to avoid them.
  • A design pattern to manage dynamic memory safely (RAII without smart pointers).
  • A reusable ScopedPointer class to emulate unique_ptr in old C++.

Apr 11, 2025
Read More
Tutorial

Deep Copy in C++: How to Avoid Shallow Copy Pitfalls

This tutorial covers:

  • What shallow vs deep copy means
  • The problems caused by shallow copy
  • How to implement deep copy correctly
  • A practical class example with dynamic memory
  • When to use Rule of Three vs Rule of Five

Apr 11, 2025
Read More
Tutorial

🛡️ Protect Your Forms Like a Pro: Anti-Spam Techniques That Actually Work

Even though CSRF isn’t about spam exactly, CSRF tokens prevent cross-site attacks, which bots might exploit.

Most frameworks like Laravel, Django, or Express have CSRF protection built-in—use it.

Apr 04, 2025
Read More
Tutorial

Build a Custom Rate Limiter in Node.js with Redis

After 100 requests within an hour, you’ll get:

{
  "error": "Too many requests. Try later."
}

Apr 04, 2025
Read More
Tutorial
javascript

Building a Real-Time Object Detection Web App with TensorFlow.js and p5.js

let video;
let detector;
let detections = [];

function setup() {
  // Create the canvas to match the video dimensions
  createCanvas(640, 480);
  // Capture video from the webcam
  video = createCapture(VIDEO);
  video.size(640, 480);
  video.hide();

  // Load the pre-trained COCO-SSD model
  cocoSsd.load().then(model => {
    detector = model;
    console.log("Model Loaded!");
    // Begin detecting objects every frame
    detectObjects();
  });
}

function detectObjects() {
  detector.detect(video.elt).then(results => {
    detections = results;
    // Continue detection in a loop
    detectObjects();
  });
}

function draw() {
  // Draw the video
  image(video, 0, 0);

  // Draw detection boxes and labels if available
  if (detections) {
    for (let i = 0; i < detections.length; i++) {
      let object = detections[i];
      stroke(0, 255, 0);
      strokeWeight(2);
      noFill();
      rect(object.bbox[0], object.bbox[1], object.bbox[2], object.bbox[3]);
      noStroke();
      fill(0, 255, 0);
      textSize(16);
      text(object.class, object.bbox[0] + 4, object.bbox[1] + 16);
    }
  }
}
  • Setup: The setup function initializes the canvas and video capture. The video is hidden by p5.js’s default element so that we can draw it onto the canvas manually.
  • Model Loading: We load the COCO-SSD model asynchronously. Once the model is ready, we start continuous object detection by calling detectObjects().
  • Detection Loop: The detectObjects function uses the loaded model to analyze the current video frame and stores the detection results. It recursively calls itself so that new frames are analyzed continuously.
  • Drawing: In the draw loop, the video feed is displayed and for each detected object, a rectangle and label are drawn. The bounding box coordinates and object class are provided by the model.

Feb 12, 2025
Read More
Tutorial

Building a Cross-Platform Desktop App with Tauri and Svelte: A Step-by-Step Tutorial

This command creates a fresh Svelte application in the tauri-svelte-app directory and installs all required dependencies.

Inside your Svelte project, initialize Tauri by running:

Feb 12, 2025
Read More
Tutorial

Implementing a Domain-Specific Language (DSL) with LLVM and C++

#ifndef DSL_PARSER_H
#define DSL_PARSER_H

#include "Lexer.h"
#include "AST.h"
#include <memory>

class Parser {
public:
    Parser(Lexer& lexer);
    std::unique_ptr<ASTNode> parseExpression();

private:
    Lexer& lexer;
    Token currentToken;

    void eat(TokenType type);
    std::unique_ptr<ASTNode> factor();
    std::unique_ptr<ASTNode> term();
};

#endif // DSL_PARSER_H

Implementation: Parser.cpp

Feb 12, 2025
Read More
Tutorial
python

دليل عملي: بناء روبوت دردشة (Chatbot) باستخدام Python و NLP

import random

def chatbot_response(user_input):
    user_input = preprocess(user_input)
    for question, response in qa_pairs.items():
        if question in user_input:
            return response
    return "عذراً، لا أفهم سؤالك. هل يمكنك إعادة صياغته؟"

حان وقت التفاعل مع الروبوت:

Dec 12, 2024
Read More
Tutorial
python

كيف تبدأ رحلتك مع الذكاء الاصطناعي: دليل عملي للمبتدئين

ابدأ باستكشاف الشبكات العصبية وخوارزميات التعلم العميق.

3. هل يمكنني تطبيق الذكاء الاصطناعي في مشروعي الحالي؟

Dec 12, 2024
Read More
Tutorial
dart

دليل شامل: تطوير تطبيقات باستخدام إطار العمل Flutter

لإضافة زر يقوم بتغيير النص عند الضغط عليه:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String message = 'اضغط على الزر لتغيير النص';

  void changeMessage() {
    setState(() {
      message = 'تم تغيير النص!';
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('تطبيق Flutter تفاعلي'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                message,
                style: TextStyle(fontSize: 20),
              ),
              SizedBox(height: 20),
              ElevatedButton(
                onPressed: changeMessage,
                child: Text('اضغط هنا'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Dec 12, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!