分类:随笔 日期:2020-09-04 作者:caocaofff 浏览:1084
先假设工作目录在/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 libncurses5
先初始化
./scripts/mysql_install_db --user=mysql
启动服务
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
修改默认编码为utf8mb4:
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
collation-server = utf8mb4_unicode_ci
init-connect=SET NAMES utf8mb4
character-set-server = utf8mb4
bind-address = 127.0.0.1
重启服务
/etc/init.d/mysqld stop
service mysqld start
登陆
/usr/local/mysql/bin/mysql -uroot -p
查看编码(登录后):
MariaDB [(none)]> show variables like 'character%';
+--------------------------+---------------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8mb3 |
| character_sets_dir | /data/bin/mariadb-10.6.3-linux-systemd-x86_64/share/charsets/ |
+--------------------------+---------------------------------------------------------------+
8 rows in set (0.002 sec)
CC版权: 本篇博文采用《CC 协议》,转载必须注明作者和本文链接