CentOS7配置OS自带的mysql数据库服务

2021年10月19日 881点热度 0人点赞 0条评论

今天接到同事求助,说之前的一个MySQL库报错了,远程看了下,配置可能给改乱了,反正还没有数据,不浪费时间直接卸载重装OS自带的数据库版本MariaDB吧。
以下是过程概要记录,留备后续参考。
正常情况下安装配置应该很快,但是因为之前配置较乱,导致启动时又报错了:

Oct 19 16:34:43 cw02 systemd[1]: Starting MariaDB database server...
Oct 19 16:34:43 cw02 mariadb-prepare-db-dir[18667]: Failed to get properties: Operation not permitted
Oct 19 16:34:43 cw02 mariadb-prepare-db-dir[18667]: Failed to get properties: Operation not permitted
Oct 19 16:34:43 cw02 mariadb-prepare-db-dir[18667]: Database MariaDB is not initialized, but the directory /var/lib/mysql is not empty, so initialization cannot be done.
Oct 19 16:34:43 cw02 mariadb-prepare-db-dir[18667]: Make sure the /var/lib/mysql is empty before running mariadb-prepare-db-dir.
Oct 19 16:34:43 cw02 systemd[1]: mariadb.service: control process exited, code=exited status=1
Oct 19 16:34:43 cw02 systemd[1]: Failed to start MariaDB database server.
Oct 19 16:34:43 cw02 systemd[1]: Unit mariadb.service entered failed state.
Oct 19 16:34:43 cw02 systemd[1]: mariadb.service failed.

根据提示干脆来一次初始化吧,清理数据目录,执行初始化:

[root@cw02 lib]# mysql_install_db
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
211019 16:45:23 [Note] /usr/libexec/mysqld (mysqld 5.5.60-MariaDB) starting as process 19428 ...
OK
Filling help tables...
211019 16:45:24 [Note] /usr/libexec/mysqld (mysqld 5.5.60-MariaDB) starting as process 19437 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h cw02 password 'new-password'

Alternatively you can run:
'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

初始化以后,此时竟然无法启动服务,查看log提示目录权限问题,修改目录权限即可:
[root@cw02 lib]# chown -R mysql.mysql mysql
[root@cw02 lib]# systemctl start mariadb
[root@cw02 lib]# systemctl status mariadb.service -l
至此库启动了。

做安全配置修改:
mysql_secure_installation

最后停库,将数据库目录移至大文件系统,改配置、启库,ok

liking

这个人很懒,什么都没留下

文章评论