MariaDB 的安装与配置

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: 这个是本人最早接触的一篇数据库配置,也是让我入门Linux基础环境搭建的一篇,有时候忘了命令也会参考里面的内容# rpm -ivh 12-cmake-2.8.11.1-5.


这个是本人最早接触的一篇数据库配置,也是让我入门Linux基础环境搭建的一篇,有时候忘了命令也会参考里面的内容


# rpm -ivh 12-cmake-2.8.11.1-5.1.x86_64.rpm 

warning: cmake-2.8.11.1-5.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 6aaf6b3f: NOKEY

Preparing...                (10########################################### [100%]

   1:cmake                   (  ########################################### [100%]

#tar -zxvf 13-mariadb-5.5.48-linux-glibc_214-x86_64.tar.gz

# mv mariadb-5.5.48-linux-x86_64 /usr/local/

# groupadd mysql

# useradd -g mysql mysql

# id mysql

uid=500(mysql) gid=500(mysql) groups=500(mysql)

# ln -s mariadb-5.5.48-linux-x86_64/ mysql

# cd mysql/

#cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

# ./scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...

160227  0:23:45 [Note] ./bin/mysqld (mysqld 5.5.48-MariaDB) starting as process 1105 ...OK

Filling help tables...

160227  0:23:47 [Note] ./bin/mysqld (mysqld 5.5.48-MariaDB) starting as process 1112 ...OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

#cp support-files/mysql.server /etc/init.d/

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !

To do so, start the server, then issue the following commands:


启动数据库:

#/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --user=mysql &

'./bin/mysqladmin' -u root password 'new-password'

'./bin/mysqladmin' -u root -h php.myfamily password 'new-password'

Alternatively you can run:

'./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 '.' ; ./bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl

cd './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

Support MariaDB development by buying support/new features from MariaDB

Corporation Ab. You can contact us about this at sales@mariadb.com.

Alternatively consider joining our community based development effort:

http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

# chown -R root .

# chown -R mysql data

# vi .bash_profile 

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin/:/usr/local/apache2/bin/:/usr/local/php/bin/

:wq


启动数据库:

#/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --user=mysql &


设置开机自动启动数据库:

#vi /etc/rc.local

add

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --user=mysql &

:wq


#reboot


修改mysql root密码:

#'./bin/mysqladmin' -u root password 'new-password'

or

# ./mysql_secure_installation 

# ./bin/mysql -u root -p

Enter password: 

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 3

Server version: 5.5.48-MariaDB MariaDB Server

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

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

MariaDB [(none)]>

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.00 sec)

MariaDB [(none)]> use mysql;

Database changed

MariaDB [mysql]> show tables;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                        |

| event                     |

| func                      |

| general_log               |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| host                      |

| ndb_binlog_index          |

| plugin                    |

| proc                      |

| procs_priv                |

| proxies_priv              |

| servers                   |

| slow_log                  |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

24 rows in set (0.00 sec)

MariaDB [mysql]> select host, user from user;

+--------------+------+

| host         | user |

+--------------+------+

| 127.0.0.1    | root |

| ::1          | root |

| localhost    |      |

| localhost    | root |

| php.myfamily |      |

| php.myfamily | root |

+--------------+------+

6 rows in set (0.00 sec)

MariaDB [mysql]> update user set host='%' where user='root' and host='localhost';

Query OK, 1 row affected (0.05 sec)

Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> select host, user from user;

+--------------+------+

| host         | user |

+--------------+------+

| %            | root |

| 127.0.0.1    | root |

| ::1          | root |

| localhost    |      |

| php.myfamily |      |

| php.myfamily | root |

+--------------+------+

6 rows in set (0.00 sec)

MariaDB [mysql]> delete from user where user='';

Query OK, 2 rows affected (0.03 sec)


修改数据库密码:

mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; 

MariaDB [mysql]> select host, user, password from user;

+--------------+------+-------------------------------------------+

| host         | user | password                                  |

+--------------+------+-------------------------------------------+

| %            | root | *0D2B78B43FD0518B55EFD87FC2C1FB6775F8AB07 |

| php.myfamily | root | *0D2B78B43FD0518B55EFD87FC2C1FB6775F8AB07 |

| 127.0.0.1    | root | *0D2B78B43FD0518B55EFD87FC2C1FB6775F8AB07 |

| ::1          | root | *0D2B78B43FD0518B55EFD87FC2C1FB6775F8AB07 |

+--------------+------+-------------------------------------------+

4 rows in set (0.00 sec)

MariaDB [mysql]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> exit

Bye

MariaDB [mysql]> flush privileges;

Query OK, 0 rows affected (0.00 sec)


修改防火墙配置;

# vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

:wq


如果遇到下面的错误:

ERROR 1045 (28000): Access denied for user 'root'@'localhost'

ps -ef | grep mysqld

查询确认mysql的pid,然后kill -9 xx

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 

# mysql -u root mysql 

mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; 

mysql> FLUSH PRIVILEGES; 

mysql> quit 

# /etc/init.d/mysql restart 

# mysql -uroot -p 

Enter password: <输入新设的密码newpassword> 

mysql> 



相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
关系型数据库 MySQL Linux
Linux(centos 7.5)服务器安装MariaDB
Linux(centos 7.5)服务器安装MariaDB
205 0
|
9月前
|
缓存 关系型数据库 MySQL
MariaDB的安装与配置
MariaDB的安装与配置
462 0
|
19天前
|
存储 关系型数据库 MySQL
源码包安装mariadb
**MariaDB**是MySQL的一个开源分支,由社区维护,提供高性能、安全且与MySQL高度兼容的数据库解决方案。它使用XtraDB和Maria存储引擎替代InnoDB和MyISAM。特点是开源、高性能、兼容性和安全性,广泛应用于各种场景和操作系统。在Redhat 9.2上安装MariaDB 10.6.17,首先配置yum源,检查现有MySQL/MariaDB,安装依赖包,下载源码,解压并配置编译环境,使用cmake和make编译安装,初始化数据库,创建用户,设置密码,添加启动脚本至开机自启,并执行安全初始化设置。
25 0
|
2月前
|
网络协议 关系型数据库 MySQL
安卓手机termux上安装MariaDB数据库并实现公网环境下的远程连接
安卓手机termux上安装MariaDB数据库并实现公网环境下的远程连接
|
8月前
|
关系型数据库 Linux 网络安全
Linux系统下安装mariaDB数据库及防火墙
Linux系统下安装mariaDB数据库及防火墙
118 0
|
5月前
|
SQL 关系型数据库 MySQL
centos编译安装mariadb
一般我不太愿意用mysql,那个玩意,有的时候不太友好。 我还是比较喜欢mariadb。
141 0
|
8月前
|
关系型数据库 MySQL Linux
如何在CentOS 7服务器上配置使用MariaDB的Galera集群:
如何在CentOS 7服务器上配置使用MariaDB的Galera集群:
|
9月前
|
存储 关系型数据库 MySQL
mysql--Centos安装MariaDB(mysql)
mysql--Centos安装MariaDB(mysql)
1393 0
|
9月前
|
Ubuntu 关系型数据库 MySQL
Ubuntu安装MariaDB-10.3数据库(等同于Mysql-5.7)
Ubuntu安装MariaDB-10.3数据库(等同于Mysql-5.7)
198 0
|
11月前
|
关系型数据库 Linux 网络安全
【主从数据库?】centos7,快速配置Mariadb主从
【主从数据库?】centos7,快速配置Mariadb主从
247 0

推荐镜像

更多