MariaDB 二进制安装

mariadb 二进制安装步骤:
  1. 安装包下载
    下载地址为:https://downloads.mariadb.org/
      这里选择版本10.3.13版,进入后根据计算机位数选择,这里下载适用于64位操作系统Linux x86_64版本。这里下载包含glibc和不包含glibc的都是可以的,如果下载包含glibc的,那么系统的glibc版本要满足要求,这里要大于2.14,一般系统是可以满足的。我们下载:mariadb-10.3.13-linux-x86_64.tar.gz

  2. 解压安装包
    将下载好的安装包上传到服务器临时目录 /soft
    解压:
    tar -xvf mariadb-10.3.13-linux-x86_64.tar.gz
    将解压之后的包剪切到安装目录
    剪切:
    mv mariadb-10.3.13-linux-x86_64 /usr/local/mariadb

  3. 创建用户和工作目录
    useradd mysql
    mkdir -p /home/mariadb8306/mariadb8306
    mkdir -p /home/mariadb8306/logs/
    chown -R mysql:mysql /home/mariadb8306

  4. 配置文件
    备份原始的/etc/my.cnf
    mv /etc/my.cnf /etc/my.cnf_bak
    vim /etc/my.cnf

[client]
port                  = 8306
socket                = /tmp/mysql8306.sock
default_character_set = utf8

[mysqld]
basedir                         = /usr/local/mariadb
datadir                         = /home/mariadb8306/mariadb8306
log_error                       = /home/mariadb8306/logs/mysql-error.log
pid-file                        = /home/mariadb8306/mariadb8306.pid
tmpdir                          = /tmp
character_set_server            = utf8
#collation_server                = utf8
port                            = 8306
socket                          = /tmp/mysql8306.sock
skip-external-locking

key_buffer_size                 = 16M
max_allowed_packet              = 16M
thread_stack                    = 192K
thread_cache_size               = 8
table_open_cache                = 64
sort_buffer_size                = 512K
net_buffer_length               = 8K
read_buffer_size                = 256K
read_rnd_buffer_size            = 512K
myisam_sort_buffer_size         = 8M
query_cache_limit               = 1M
query_cache_size                = 16M
log-bin                         = mysql-bin
binlog_format                   = mixed
server-id                       = 12488306
default-storage-engine          = MyISAM
default-tmp-storage-engine      = MYISAM

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
default_character_set = utf8

[myisamchk]
key_buffer_size  = 20M
sort_buffer_size = 20M
read_buffer      = 2M
write_buffer     = 2M

[mysqlhotcopy]
interactive-timeout

注意:文件内容根据实际生产环境合理设置,我这里是小型库,仅供参考

  1. 数据库初始化
    /usr/local/mariadb/scripts/mysql_install_db --user=mysql
    配置文件默认是/etc/my.cnf,如果配置文件不是这个需要加参数说明–defaults-file=/etc/my.cnf。这里使用的是默认文件,不带参数。
    以下是初始化过程,出现OK后说名初始化成功。
[root@vm-zentao scripts]# /usr/local/mariadb/scripts/mysql_install_db --user=mysql

Installing MariaDB/MySQL system tables in '/home/mariadb8306/mariadb8306' ...
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/local/mariadb/bin/mysqladmin' -u root password 'new-password'
'/usr/local/mariadb/bin/mysqladmin' -u root -h vm-zentao password 'new-password'

Alternatively you can run:
'/usr/local/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 '/usr/local/mariadb' ; /usr/local/mariadb/bin/mysqld_safe --datadir='/home/mariadb8306/mariadb8306'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/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/
  1. 启动数据库
    /usr/local/mariadb/bin/mysqld_safe --user=mysql &
    同理,默认配置文件为/etc/my.cnf
    查看服务是否启动成功
    ps -ef|grep mysql

  2. 修改环境变量
    vim /etc/profile
    export PATH=$PATH:/usr/local/mariadb/bin

source /etc/profile

  1. 配置mysqld 服务
    添加mysql到系统服务目录: cp support-files/mysql.server /etc/init.d/mysqld
      如果是之前安装过mysql,那么现在就已经启动了,第一次安装需要手动启动服务: /etc/init.d/mysqld start
      添加mysqld到系统服务,随系统一起启动: chkconfig mysqld on
      查看mysql服务运行状态: systemctl status mysqld.service
    注意:在redhat8系统上执行mysql进入客户端时可能会提示找不到libncurses.so的错误这个时候只需要安装一下开发包就可以了,安装的命令为: yum install libncurses* ,安装成功之后再次进入就可以了.

  2. 修改root密码(安装后root 密码为空)
    msyql(回车) 链接数据库库
    MariaDB [(none)]>use mysql;
    MariaDB [mysql]>select User,Host,Password from user;(查询结果,密码列为空)
    MariaDB [mysql]>update user set password=password(‘123456’) where user=‘root’ and host=‘localhost’;
    MariaDB [mysql]>flush privileges;
    MariaDB [mysql]>select User,Host,Password from user;(查询结果,密码有值)

重新登陆
mysql -uroot -p123456

创建一个host=% 的权限(从任意IP登陆)
MariaDB [mysql]> create user ‘root’@’%’ identified by ‘123456’;
MariaDB [mysql]> grant all on . to root@’%’;
MariaDB [mysql]> flush privileges;

如果报错连不上,看是不是服务器防火墙没关(centOS 7)
systemctl status firewalld.service
systemctl stop firewalld.service
chkconfig firewalld off (开机不启动)

修改数据库默认字符集
ALTER DATABASE ‘TEST’ DEFAULT CHARACTER SET UTF8;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值