在Ubuntu上手动部署mariadb数据库环境

分类:随笔 日期:2020-09-04 作者:caocaofff 浏览:129

先假设工作目录在/data/bin

mkdir -p /data/bin
cd /data/bin
#添加用户
groupadd mysql
useradd -s /sbin/nologin -g mysql mysql
#环境变量
vim /etc/profile

export MARIADB=/usr/local/mysql
export PATH=$MARIADB/bin:$PATH
最新版mariadb数据库下载地址:http://ftp.hosteurope.de/mirror/archive.mariadb.org/

wget http://ftp.hosteurope.de/mirror/archive.mariadb.org/mariadb-10.5.5/bintar-linux-systemd-x86_64/mariadb-10.5.5-linux-systemd-x86_64.tar.gz
tar -zxf mariadb-10.5.5-linux-systemd-x86_64.tar.gz
cd mariadb-10.5.5-linux-systemd-x86_64
#目录权限
chown -R root:root .
chown -R mysql data
#目录必须是绝对路径
ln -sf /data/bin/mariadb-10.5.2-linux-systemd-x86_64 /usr/local/mysql
#复制配置文件,非必须
cp support-files/my-small.cnf /etc/my.cnf

如果提示缺少libaio.so.1可以

apt install libaio1

先临时启动服务

cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
服务自启动
update-rc.d mysqld defaults

开始初始化

/usr/local/mysql/bin/mysql_secure_installation

以下是初始化设置的参考:

Enter current password for root (enter for none):<–初次运行直接回车 OK, successfully
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
Remove anonymous users? [Y/n] <–是否删除匿名用户,生产环境建议删除,所以直接回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
Remove test database and access to it? [Y/n] <– 是否删除test数据库,直接回车
Reload privilege tables now? [Y/n] <–是否重新加载权限表,直接回车

vim /etc/my.cnf

修改默认编码为UTF-8:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
重启服务

/etc/init.d/mysqld stop
service mysqld start

登陆

/usr/local/mysql/bin/mysql -uroot -p

查看编码(登录后):

show variables like 'character%';
Variable_nameValue
character_set_clientutf8
character_set_connectionutf8
character_set_databaseutf8
character_set_filesystembinary
character_set_resultsutf8
character_set_serverutf8
character_set_systemutf8
character_sets_dir/data/bin/mariadb-10.5.5-linux-systemd-x86_64/share/charsets/

8 rows in set (0.002 sec)

评论 (暂无评论)

发表评论

昵称:  
邮箱:  
网址: