创建用户
groupadd mysql
useradd -g mysql mysql
删除原来的包
# rpm -qa|grep mysql
# rpm -qa|grep mari
mariadb-libs-5.5.68-1.el7.x86_64
# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
解压
cd /usr/local & mkdir mysql
cd mysql
# cp mysql-8.0.34-linux-glibc2.12-x86_64.tar.gz /home/mysql/
# cd /home/mysql/
chown mysql:mysql mysql-8.0.34-linux-glibc2.12-x86_64.tar.gz
chmod 775 mysql-8.0.34-linux-glibc2.12-x86_64.tar.gz
su - mysql
tar -xvf mysql-8.0.34-linux-glibc2.12-x86_64.tar.gz
mv mysql-8.0.34-linux-glibc2.12-x86_64 mysql834
创建通用目录
ln -s /home/mysql/mysqlbase /usr/local/mysql
cd /usr/local/mysql/mysql834
# ls -lrt
total 308
-rw-r--r-- 1 mysql mysql 666 Jun 22 19:07 README
-rw-r--r-- 1 mysql mysql 279815 Jun 22 19:07 LICENSE
drwxr-xr-x 2 mysql mysql 4096 Jun 22 20:25 support-files
drwxr-xr-x 28 mysql mysql 4096 Jun 22 20:25 share
drwxr-xr-x 4 mysql mysql 4096 Jun 22 20:25 man
drwxr-xr-x 6 mysql mysql 4096 Jun 22 20:25 lib
drwxr-xr-x 3 mysql mysql 4096 Jun 22 20:25 include
drwxr-xr-x 2 mysql mysql 4096 Jun 22 20:25 docs
drwxr-xr-x 2 mysql mysql 4096 Jun 22 20:25 bin
# mkdir /data
# chown mysql:mysql /data
# chmod 775 /data
su - mysql
配置root
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/mysqlbase/bin:/usr/local/mysql/mysqlbase/lib
source /etc/profile
编写配置文件
mysql> prompt \R:\m:\s \U[\d]>
shell> export MYSQL_PS1="(\u@\h) [\d]> "
shell> mysql --prompt="(\u@\h) [\d]> "
prompt=(\\u@\\h) [\\d]>\\_
port=3306
default-character-set = utf8mb4
socket = /tmp/mysql.sock
[mysql]
prompt="\R:\m:\s [\d]> "
no-auto-rehash
max_allowed_packet = 256M
[mysqld]
server-id=1
port=3306
basedir=/usr/local/mysql/mysqlbase
datadir=/data
socket=/tmp/mysql.sock
log-error=/data/mysqld.log
pid-file=/data/mysqld.pid
user=mysql
character_set_server = utf8mb4
collation_server = utf8mb4_general_ci
default-storage-engine = InnoDB
autocommit = on
event_scheduler = ON
log_error = /home/mysql/error.log
lower_case_table_names = 1
back_log=2000
connect_timeout=15
skip_name_resolve=ON
max_connections=5000
table_definition_cache=2000
table_open_cache=10000
ssl=0
slow_query_log = ON
slow_query_log_file = /data/slow.log
# Innodb
innodb_buffer_pool_size = 10240M
innodb_buffer_pool_instances=8
innodb_log_file_size = 1024M --已经过期
innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 20
innodb_autoinc_lock_mode=2
innodb_read_io_threads = 5
innodb_write_io_threads = 5
innodb_thread_concurrency = 8
innodb_doublewrite=1
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = 'O_DIRECT'
innodb-page-cleaners=8
innodb_purge_threads=4
innodb_lru_scan_depth=2048
innodb_io_capacity=8000
innodb_io_capacity_max=16000
innodb_adaptive_hash_index=OFF
innodb-change-buffering=none
innodb_flush_neighbors=0
innodb_max_dirty_pages_pct = 90
innodb_max_dirty_pages_pct_lwm = 10
innodb_file_per_table = ON
# Binlog
relay-log=relay-1
enforce-gtid-consistency
gtid-mode=on
binlog_cache_size = 1024M
#master-info-repository=TABLE
#relay-log-info-repository=TABLE
binlog-checksum=NONE
log-bin
sync_binlog=1
# Monitoring
innodb_monitor_enable='%'
performance_schema=ON
performance_schema_instrument='%synch%=on'
初始化数据库
./mysqld --user=mysql --basedir=/usr/local/mysql/mysqlbase --datadir=/data --initialize
./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.11' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./mysqld)
./mysqld: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by ./mysqld)
./mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ./mysqld)
./mysqld: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by /home/mysql/mysql834/bin/../lib/private/libcrypto.so.3)
./mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /home/mysql/mysql834/bin/../lib/private/libprotobuf-lite.so.3.19.4)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /home/mysql/mysql834/bin/../lib/private/libprotobuf-lite.so.3.19.4)
./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /home/mysql/mysql834/bin/../lib/private/libprotobuf-lite.so.3.19.4)
./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /home/mysql/mysql834/bin/../lib/private/libprotobuf-lite.so.3.19.4)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /home/mysql/mysql834/bin/../lib/private/libprotobuf-lite.so.3.19.4)
自启动配置
/usr/local/mysql/mysqlbase下执行
cp -a ./support-files/mysql.server /etc/init.d/mysql
cp -a ./support-files/mysql.server /etc/init.d/mysqld
chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysql
chmod +x /etc/init.d/mysqld
service mysqld status
service mysqld start
# service mysqld start
/etc/init.d/mysqld: line 239: my_print_defaults: command not found
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
basedir出错修改后restart后即可
# service mysqld restart
mysqld safe启动数据库
# ./mysqld_safe --user=mysql --basedir=/usr/local/mysql/mysqlbase --datadir=/data &
[1] 22115
# 2024-07-04T13:24:11.353388Z mysqld_safe Logging to '/home/mysql/error.log'.
root 22115 13926 0 15:45 pts/0 00:00:00 /bin/sh ./mysqld_safe --user=mysql --basedir=/usr/local/mysql/mysql833 --datadir=/data
mysql 22943 22115 41 15:45 pts/0 00:00:03 /usr/local/mysql/mysql833/bin/mysqld --basedir=/usr/local/mysql/mysql833 --datadir=/data --plugin-dir=/usr/local/mysql/mysql833/lib/plugin --user=mysql --log-error=/home/mysql/error.log --pid-file=/data/mysqld.pid --socket=/tmp/mysql.sock --port=3306
root 23003 13926 0 15:45 pts/0 00:00:00 grep --color=auto mysq
启动mysql改root密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword'
脚本调整
/data/mysql/bin/mysqld_safe --user=mysql --basedir=/data/mysql --datadir=/data/mysqldata &
/data/mysql/bin/mysql -uroot -p"Tjyd@_123$" << eof
shutdown;
eof