我要评分
获取效率
正确性
完整性
易理解

Running

After MariaDB is installed, you can configure database files, start the database, manage users, and stop the database to check whether the database is running properly.

The installation directories for both installation methods (source code compilation and RPM package installation) are the same. The default directory is /usr/local/mariadb.

  1. Modify the configuration file.
    1. Modify the my.cnf file and change the file paths (including the software installation path basedir and data path datadir) based on actual requirements.
      1
      2
      rm -f /etc/my.cnf
      echo -e "[mysqld_safe]\nlog-error=/data/mariadb/log/mysql.log\npid-file=/data/mariadb/run/mysqld.pid\n[mysqldump]\nquick\n[mysql]\nno-auto-rehash\n[mysqld]\nbasedir=/usr/local/mariadb\ntmpdir=/data/mariadb/tmp\ndatadir=/data/mariadb/data\nsocket=/data/mariadb/run/mysql.sock\ncharacter-set-server=utf8\ndefault_authentication_plugin=mysql_native_password\nport=3306\nuser=mysql\n" > /etc/my.cnf
      
    2. Check that the my.cnf file is correctly modified.
      1
      cat /etc/my.cnf
      

      If user mysql (OS user) is configured in the my.cnf file, the corresponding mysql user (database user) will be created when the database is initialized.

    3. Change the group and user of the /etc/my.cnf file to mysql:mysql.
      1
      chown mysql:mysql /etc/my.cnf
      
  2. Set the environment variables.
    1. After the compilation and installation are complete, add the path of the MariaDB binary file to the PATH environment variable.

      In the following command, /usr/local/mariadb/bin is the absolute path of the binary file in the installation directory. Replace it with the actual one.

      1
      echo export PATH=$PATH:/usr/local/mariadb/bin >> /etc/profile
      
    2. Make the environment variable settings take effect.
      1
      source /etc/profile
      
  3. Initialize the database.
    1
    /usr/local/mariadb/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb/data
    

    If the paths are changed during the installation, change the paths according to the actual situation.

    If the initialization fails and the message "--initialize specified but the data directory has files in it." is displayed, run the following command to delete the data and initialize the database again.

    1
    2
    3
    ls /data/mariadb/data
    cd /data/mariadb/data/
    rm -rf *
    
  4. Start the database.

    The mysqld_safe script monitors the running status of the MariaDB service after the MariaDB service is started, and restarts the service when it breaks down. You can also run the following command to directly start the MariaDB service:

    /usr/local/mariadb/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb/data &
    1. Run the following command to start the MariaDB service and press Enter:
      1
      /usr/local/mariadb/bin/mysqld_safe --defaults-file=/etc/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb/data &
      

    2. Check whether the process has been started.
      1
      ps -ef | grep mysql
      

  5. Switch to user mysql.
    1
    2
    su - mysql
    whoami
    
  6. Log in to the database. Password is not required for the first login.
    1
    /usr/local/mariadb/bin/mysql -uroot -S /data/mariadb/run/mysql.sock
    

    Check the database users.

    1
    2
    3
    use mysql;
    show tables;
    select user,host from user;
    

  7. Configure the database user name and password.
    1. After logging in to the database, change the password of the root user for logging in to the database.
      1
      alter user 'root'@'localhost' identified by "123456";
      
    2. Create a root user for all the other hosts in the domain.
      1
      create user 'root'@'%' identified by '123456';
      
    3. Grant permissions.
      1
      2
      grant all privileges on *.* to 'root'@'%';
      flush privileges;
      
    4. Exit from the database.
      1
      exit
      
  8. Log in to the database using a password.
    1
    /usr/local/mariadb/bin/mysql -uroot -p123456 -S /data/mariadb/run/mysql.sock
    

  9. Exit the database.
    \q

    or

    exit
  10. Optional: Stop the database.
    1
    /usr/local/mariadb/bin/mysqladmin -uroot -p123456  shutdown -S /data/mariadb/run/mysql.sock