1.路径规划与创建
数据文件存储位置 /data/mysql/data
日志文件存储位置 /data/logs/mysql
binlog文件存储位置 /data/mysql
缓存目录位置 /dta/tmp
1 2 3 4
| mkdir -p /data/mysql/data mkdir -p /data/logs/mysql mkdir -p /data/logs/tmp mkdir -p /data/tmp
|
2.创建用户配置权限
1 2 3 4 5 6 7
| useradd mysql chown -R mysql:mysql /data/mysql chown -R mysql:mysql /data/logs chown -R mysql:mysql /data/tmp chmod -R 775 /data/mysql chmod -R 775 /data/logs chmod -R 775 /data/tmp
|
3.上传安装包与依赖包并解压
安装包:
https://downloads.mariadb.org/mariadb/+releases/
依赖包:
https://pan.baidu.com/s/1neVvaAUbeQ1xIj7bIUtSKA 提取码:ydx0
上传mariadb-10.5.8-linux-systemd-x86_64.tar.gz至/tmp
tar zxvf mariadb-10.5.8-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
把libtinfo.so.5依赖包放在该目录下:
/lib/x86_64-linux-gnu/
mv mariadb-10.5.8-linux-x86_64/ mysql
4.修改配置文件
vim /etc/my.cnf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| [client] port = 3306 socket = /tmp/mysql.sock
[mysqld] user = mysql datadir = /data/mysql/data pid-file = /data/mysql/mysql.pid server-id = 50 relay_log =/data/logs/mysql/mysql_relay.log bind-address = 0.0.0.0
tmpdir=/data/tmp #当数据库是大量存储时建议指向TMP目录,否则做全表操作时临时空间会不足
init_connect ='SET NAMES utf8' character-set-server = utf8 skip-name-resolve back_log = 300
max_connections = 8019 max_connect_errors = 1024000 open_files_limit = 65535 table_open_cache = 2048 max_allowed_packet = 50M max_heap_table_size = 512M tmp_table_size = 256M
read_buffer_size = 2M read_rnd_buffer_size = 16M sort_buffer_size = 8M join_buffer_size = 8M key_buffer_size = 512M thread_cache_size = 128
query_cache_type = 2 query_cache_size = 128M query_cache_limit = 5M thread_stack = 192k ft_min_word_len = 4
log_bin = /data/mysql/mysql_bin.log binlog_format = ROW expire_logs_days = 7
log_error = /data/logs/mysql/mysql_error.log slow_query_log = 1 long_query_time = 1 log_slow_verbosity=query_plan slow_query_log_file = /data/logs/mysql/mysql_slow.log performance_schema = 0
skip-external-locking #跳过外部锁定,避免external locking
bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1
# default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 2048M innodb_write_io_threads = 8 innodb_read_io_threads = 8 innodb_thread_concurrency = 16 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 8M innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 10 innodb_autoinc_lock_mode = 2 innodb_doublewrite = 1 # innodb_rollback_on_timeout = 1 innodb_force_recovery=0 interactive_timeout = 28800 wait_timeout = 120
[mysqldump] quick max_allowed_packet = 16M
[myisamchk] key_buffer_size = 512M sort_buffer_size = 8M read_buffer = 4M write_buffer = 4M
|
5.初始化数据库
1
| /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
|
6.设置启动文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
7.启动数据库
/etc/init.d/mysql start
8.配置环境变量
vim /etc/profile
1 2 3
| #在最后面添加 export MYSQL_HOME=/usr/local/mysql export PATH=$MYSQL_HOME/bin:$PATH
|
source /etc/profile
9.使用无密码登录,添加登录密码
mysql
无密码登录使用如下命令:
1 2
| ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("admin"); flush privileges;
|
之后用密码正常登录即可