mariadb5.5.56在centos7.6环境安装

mariadb5.5.56在centos7.6环境安装

1 下载安装包

https://mariadb.org/mariadb/all-releases/#5-5

2 上传安装包的服务器

mariadb-5.5.56-linux-systemd-x86_64.tar.gz

3 解压安装包

复制代码
tar -zxvf mariadb-5.5.56-linux-systemd-x86_64.tar.gz
mv mariadb-5.5.56-linux-systemd-x86_64 /mariadb

4 创建data目录

复制代码
mkdir -p /data/mariadb_5_5_56

5 修改my.cnf

复制代码
cp /mariadb/support_files/my-small.cnf /etc/my.cnf

# cat /etc/my.cnf|grep -Ev "^$|^#"
[client]
port            = 3306
socket          = /tmp/mysql.sock
[mysqld]
basedir         = /mariadb
datadir         = /data/mariadb_5_5_56
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
server-id       = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout

6 初始化数据库

复制代码
# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb_5_5_56
Installing MariaDB/MySQL system tables in '/data/mariadb_5_5_56' ...
250607 10:46:22 [Note] /mariadb/bin/mysqld (mysqld 5.5.56-MariaDB) starting as process 16500 ...
OK
Filling help tables...
250607 10:46:23 [Note] /mariadb/bin/mysqld (mysqld 5.5.56-MariaDB) starting as process 16509 ...
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:

'/mariadb/bin/mysqladmin' -u root password 'new-password'
'/mariadb/bin/mysqladmin' -u root -h exam01 password 'new-password'

Alternatively you can run:
'/mariadb/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 '/mariadb' ; /mariadb/bin/mysqld_safe --datadir='/data/mariadb_5_5_56'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/mariadb/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/

---------------------------------------------------------------
[root@exam01 soft]# cd /data/mariadb_5_5_56/
[root@exam01 mariadb_5_5_56]# ll
total 28
-rw-rw---- 1 mysql mysql 16384 Jun  7 10:46 aria_log.00000001
-rw-rw---- 1 mysql mysql    52 Jun  7 10:46 aria_log_control
drwx------ 2 mysql root   4096 Jun  7 10:46 mysql
drwx------ 2 mysql mysql  4096 Jun  7 10:46 performance_schema
drwx------ 2 mysql root      6 Jun  7 10:46 test

7 配置启动服务

复制代码
cd support_files
cp mysql.server /etc/init.d/mariadb
vi /etc/init.d/mariadb
修改basedir ,datadir路径

8 加载并启动服务

复制代码
[root@exam01 support-files]# systemctl  daemon-reload
[root@exam01 mariadb]# systemctl start mariadb
[root@exam01 mariadb]# systemctl status mariadb
● mariadb.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mariadb; bad; vendor preset: disabled)
   Active: active (running) since Sat 2025-06-07 11:02:35 CST; 1s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 17652 ExecStart=/etc/rc.d/init.d/mariadb start (code=exited, status=0/SUCCESS)
    Tasks: 20
   Memory: 79.3M
   CGroup: /system.slice/mariadb.service
           ├─17666 /bin/sh /mariadb/bin/mysqld_safe --datadir=/data/mariadb_5_5_56 --pid-file=/data/mariadb_5_5_56/exam01.pid
           └─17936 /mariadb/bin/mysqld --basedir=/mariadb --datadir=/data/mariadb_5_5_56 --plugin-dir=/mariadb/lib/plugin --user=mysql --log...

Jun 07 11:02:32 exam01 systemd[1]: Starting LSB: start and stop MySQL...
Jun 07 11:02:33 exam01 mariadb[17652]: Starting MySQL.250607 11:02:33 mysqld_safe Logging to '/data/mariadb_5_5_56/exam01.err'.
Jun 07 11:02:33 exam01 mariadb[17652]: 250607 11:02:33 mysqld_safe Starting mysqld daemon with databases from /data/mariadb_5_5_56
Jun 07 11:02:35 exam01 mariadb[17652]: . SUCCESS!
Jun 07 11:02:35 exam01 systemd[1]: Started LSB: start and stop MySQL.

[root@exam01 mariadb]# ps -ef |grep mariadb
root     17666     1  0 11:02 ?        00:00:00 /bin/sh /mariadb/bin/mysqld_safe --datadir=/data/mariadb_5_5_56 --pid-file=/data/mariadb_5_5_56/exam01.pid
mysql    17936 17666  0 11:02 ?        00:00:00 /mariadb/bin/mysqld --basedir=/mariadb --datadir=/data/mariadb_5_5_56 --plugin-dir=/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb_5_5_56/exam01.err --pid-file=/data/mariadb_5_5_56/exam01.pid --socket=/tmp/mysql.sock --port=3306

9 修改root密码

复制代码
[root@exam01 mariadb]# '/mariadb/bin/mysqladmin' -u root -h exam01 password 'root'

10 验证登录失败

修改完密码之后测试登录失败,不知道问题在哪

复制代码
[root@exam01 mariadb]# mysql -uroot -hlocalhost -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@exam01 mariadb]# 
[root@exam01 mariadb]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@exam01 mariadb]# 
[root@exam01 mariadb]# mysql -uroot -p -h127.0.0.1
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

11 修改密码

复制代码
窗口1
[root@exam01 ~]# cd /mariadb/bin/
[root@exam01 bin]# ./mysqld_safe --skip-grant-tables &
[1] 19686
[root@exam01 bin]# 250607 11:23:50 mysqld_safe Logging to '/data/mariadb_5_5_56/exam01.err'.
250607 11:23:50 mysqld_safe Starting mysqld daemon with databases from /data/mariadb_5_5_56


窗口2
[root@exam01 ~]# mysql -uroot -p
Enter password:      <<<<<<<<<<<<<  直接回车
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Database changed
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> update mysql.user set password=password('root') where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

12 再次登录正常

复制代码
[root@exam01 bin]# ps -ef |grep mysql
root     19686 19158  0 11:23 pts/0    00:00:00 /bin/sh ./mysqld_safe --skip-grant-tables
mysql    19944 19686  0 11:23 pts/0    00:00:00 /mariadb/bin/mysqld --basedir=/mariadb --datadir=/data/mariadb_5_5_56 --plugin-dir=/mariadb/lib/plugin --user=mysql --skip-grant-tables --log-error=/data/mariadb_5_5_56/exam01.err --pid-file=exam01.pid --socket=/tmp/mysql.sock --port=3306
root     20256 19158  0 11:28 pts/0    00:00:00 grep --color=auto mysql
[root@exam01 bin]# 
[root@exam01 bin]# 
[root@exam01 bin]# kill -9 19686 19944
[1]+  Killed                  ./mysqld_safe --skip-grant-tables
[root@exam01 bin]# 
[root@exam01 bin]# systemctl start mariadb
[root@exam01 bin]# systemctl status mariadb
● mariadb.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mariadb; bad; vendor preset: disabled)
   Active: active (running) since Sat 2025-06-07 11:28:25 CST; 5s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 20281 ExecStart=/etc/rc.d/init.d/mariadb start (code=exited, status=0/SUCCESS)
    Tasks: 20
   Memory: 49.3M
   CGroup: /system.slice/mariadb.service
           ├─20295 /bin/sh /mariadb/bin/mysqld_safe --datadir=/data/mariadb_5_5_56 --pid-file=/data/mariadb_5_5_56/exam01.pid
           └─20567 /mariadb/bin/mysqld --basedir=/mariadb --datadir=/data/mariadb_5_5_56 --plugin-dir=/mariadb/lib/plugin --user=mysql --log...

Jun 07 11:28:23 exam01 systemd[1]: Starting LSB: start and stop MySQL...
Jun 07 11:28:24 exam01 mariadb[20281]: Starting MySQL.250607 11:28:24 mysqld_safe Logging to '/data/mariadb_5_5_56/exam01.err'.
Jun 07 11:28:24 exam01 mariadb[20281]: 250607 11:28:24 mysqld_safe Starting mysqld daemon with databases from /data/mariadb_5_5_56
Jun 07 11:28:25 exam01 mariadb[20281]: . SUCCESS!
Jun 07 11:28:25 exam01 systemd[1]: Started LSB: start and stop MySQL.
[root@exam01 bin]# pwd
/mariadb/bin
[root@exam01 bin]# ./mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

附:

第10步骤 登录失败的原因已经找到,由于第9步修改密码的时候指定了host的主机名。在mysql.user表记录的是root ,exam01

复制代码
MariaDB [(none)]> use mysql;
Database changed
MariaDB [mysql]> 
MariaDB [mysql]> select user,host from user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
|      | exam01    |
| root | exam01    |   <<<<<<<<<<<<<<<<<<
|      | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.00 sec)

尝试指定host主机名是可以正常登录的。

复制代码
[root@exam01 bin]# mysql -uroot -hexam01 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 
相关推荐
Digitally1 分钟前
如何在安卓手机/平板上找到下载文件?
android·智能手机·电脑
硬件学长森哥3 小时前
Android影像基础--cameraAPI2核心流程
android·计算机视觉
MAGICIAN...6 小时前
【Redis】--持久化机制
数据库·redis·缓存
我真的是大笨蛋6 小时前
JVM调优总结
java·jvm·数据库·redis·缓存·性能优化·系统架构
前行的小黑炭8 小时前
Android 协程的使用:结合一个环境噪音检查功能的例子来玩玩
android·java·kotlin
阿华的代码王国8 小时前
【Android】内外部存储的读写
android·内外存储的读写
步步为营DotNet8 小时前
5-2EFCore性能优化
数据库·性能优化·.net
2501_920047039 小时前
Redis-集群
数据库·redis·bootstrap
半夏陌离9 小时前
SQL 拓展指南:不同数据库差异对比(MySQL/Oracle/SQL Server 基础区别)
大数据·数据库·sql·mysql·oracle·数据库架构
旋转的油纸伞9 小时前
SQL表一共有几种写入方式
数据库·sql