1、安装依赖
sudo apt install -y software-properties-common devscripts equivs cmake libncurses-dev
2、设置用户和权限
sudo groupadd mysql sudo useradd mysql -g mysql sudo mkdir -p /usr/local/mysql sudo mkdir -p /usr/local/db/mysql/data sudo mkdir -p /auth_pam_tool_dir sudo touch /auth_pam_tool_dir/auth_pam_tool sudo chown -R mysql:mysql /usr/local/mysql sudo chown -R mysql:mysql /usr/local/db/mysql/data sudo chown -R mysql:mysql /usr/local/mysql/. sudo chown -R mysql:mysql /usr/local/db/mysql/data/. sudo chown -R mysql:mysql /auth_pam_tool_dir
3、设置环境变量
sudo vi /etc/profile
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
source /etc/profile
4、安装(将 mariadb-10.8.3.tar.gz 放到 /usr/local 下)
sudo tar zxvf mariadb-10.8.3.tar.gz cd /usr/local/mariadb-10.8.3/ sudo cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/db/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=22066
在之后的make过程中会自动下载pcre2,但下载的过程很慢。现在手工下载比较快(注:每个版本的MariaDB需要的pcre2也不同)
cd /usr/local/mariadb-10.8.3/extra/pcre2/src/ sudo wget https://dsideal.obs.cn-north-1.myhuaweicloud.com/pcre2-10.40.zip
开始make
cd - sudo make -j8 sudo make install
5、设置配置文件
sudo vi /etc/my.cnf
[client] port = 22066 socket = /usr/local/mysql/mysqld.sock # The MySQL server [mysqld] port = 22066 socket = /usr/local/mysql/mysqld.sock datadir = /usr/local/db/mysql/data skip-external-locking skip-name-resolve skip-grant-tables back_log = 100 max_connections = 2048 max_connect_errors = 30 table_open_cache = 2048 open_files_limit = 16384 max_allowed_packet = 16M read_buffer_size = 8M read_rnd_buffer_size = 32M sort_buffer_size = 2M join_buffer_size = 2M thread_cache_size = 16 query_cache_size = 128M query_cache_limit = 4M slow_query_log = 1 long_query_time = 2 lower_case_table_names = 1 innodb_file_per_table = 1 max_allowed_packet = 64M server-id = 1 log-bin = mysql-bin expire_logs_days = 7 binlog_format = ROW innodb_data_file_path = ibdata1:10M:autoextend innodb_buffer_pool_size = 2G innodb_write_io_threads = 8 innodb_read_io_threads = 8 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 16M innodb_log_file_size = 170M innodb_lock_wait_timeout = 60
6、初始化数据库和复制启动脚本
cd /usr/local/mysql sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/db/mysql/data sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
重新加载服务的配置文件
sudo systemctl daemon-reload
启动
sudo systemctl start mysql
自启
sudo systemctl enable mysql
7、设置root密码
mysql
flush privileges; GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456"; flush privileges;
完成后,将my.cnf配置文件中的skip-grant-tables配置去掉,重启服务