1、下载二进制包
# 官方下载地址,根据需要下载不同版本
https://dev.mysql.com/downloads/mysql/
# 我们要下载的包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
2、初始化准备
# 校验包文件
md5sum mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
# 解压包
tar xf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
# 重命名
mv mysql-5.7.36-linux-glibc2.12-x86_64 mysql-5.7.36
# 软连接到工作目录
ln -s /sqldata/mysql-5.7.36 /usr/local/mysql
# 拷贝服务到运行目录
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# 创建用户和组
groupadd mysql && useradd mysql -M -g mysql -s /sbin/nologin
# 创建数据目录
mkdir -p /sqldata/data/
3、创建my.cnf
配置文件
[client]
port = 3306
socket = /usr/local/mysql/mysql.sock
[mysqld]
#skip-grant-tables # 忘记密码用的
symbolic-links=0
port = 3306
basedir = /usr/local/mysql
datadir = /sqldata/data/
socket = /usr/local/mysql/mysql.sock
pid-file = /usr/local/mysql/mysql.pid
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
user = mysql
bind-address = 0.0.0.0
server-id = 1
back_log = 300
max_connections = 6000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
#log_bin = /usr/local/mysql/binlogs/mysql-bin
#binlog_format = mixed
#expire_logs_days = 30
log_error = /usr/local/mysql/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /usr/local/mysql/log/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
4、初始化
这里的初始化方式是旧版本,也提示了初始化方法。
[root@sh-web bin]# cd /usr/local/mysql/bin
[root@sh-web bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/sqldata/data/
2021-11-08 15:17:58 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2021-11-08 15:17:58 [ERROR] Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2021-11-08 15:17:58 [ERROR] Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/sqldata/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --
-- server log end --
安装依赖包:libaio
numactl
[root@sh-web bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/sqldata/data/
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
再初始化则成功
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/sqldata/data/
2021-11-08T07:21:44.045974Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-08T07:21:45.010453Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-11-08T07:21:45.144905Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-11-08T07:21:45.211001Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8746bc60-4064-11ec-bc15-52540009c3a1.
2021-11-08T07:21:45.214236Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-11-08T07:21:45.827992Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-11-08T07:21:45.828010Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-11-08T07:21:45.828672Z 0 [Warning] CA certificate ca.pem is self signed.
2021-11-08T07:21:46.230792Z 1 [Note] A temporary password is generated for root@localhost: )wllhTn<i3bj
5、配置system管理启动MySQL
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/service/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
systemctl daemon-reload
6、启动数据库
#1.使用system启动
[root@db03 ~]# systemctl start mysqld
#查看进程启动失败,没有任何报错
#2.使用mysqld启动脚本启动
[root@db03 ~]# /etc/init.d/mysqld start
/etc/init.d/mysqld: line 244: my_print_defaults: command not found
/etc/init.d/mysqld: line 264: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
#原因:二进制的包是源码包已经生成编译安装完成的,在cmake阶段已经指定了所有的目录都是/usr/local/mysql,所以启动时所有程序都去找/usr/local/mysql目录,没有该目录,所以启动失败
#3.解决启动问题
1)方法一:做软连接
[root@db03 ~]# ln -s /service/mysql /usr/local/mysql
2)方法二:修改启动文件
[root@db03 ~]# vim /etc/init.d/mysqld
basedir=/service/mysql
datadir=/service/mysql/data
#4.再次测试启动
[root@db03 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
#或者
[root@db03 ~]# systemctl start mysqld
7、设置环境变量:
[root@db02 ~]# vim /etc/profile.d/mysql.sh
export PATH=/service/mysql/bin:$PATH
[root@db02 ~]# source /etc/profile
设置数据库密码:
#1.简单的设置方式
[root@db01 ~]# mysqladmin -uroot password '123'
Warning: Using a password on the command line interface can be insecure.
#2.安全的设置方式
[root@db02 ~]# mysqladmin -uroot password
New password: 123
Confirm new password: 123
#3.初始化后首次设置密码:
mysql> SET PASSWORD = PASSWORD('your_new_password');
Query OK, 0 rows affected, 1 warning (0.01 sec)
#4.如果这不是您第一次设置密码,请尝试以下方法:
mysql> UPDATE mysql.user SET Password=PASSWORD('your_new_password') WHERE User='root';
忘记密码
1. 修改my.cnf文件加入如下:
skip-grant-tables # 跳过密码
2. 重启数据库服务
3. 修改密码即可
mysql> update mysql.user set authentication_string=password('your_new_password') where user='root';
mysql> flush privileges;
恢复mysqldump备份的数据
1. 命令行交互式:
mysql -u root -p sqlfile.sql
2. 进入数据库恢复:
mysql> source /root/sqlfile.sql
最新评论
# 这只是一个创建远程登录并授权的语句、仅作为记录 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Fit2cloud!' WITH GRANT OPTION;
当MGR集群初始化结束后,需要开启MGR集群自启动(需要有一台节点是自动开启引导) loose-group_replication_start_on_boot = ON #设置节点是否在启动时自动启动 MGR 集群 loose-group_replication_bootstrap_group = ON #设置节点是否作为初始引导节点启动集群
密码:blog.sirliu.com
本内容密码:blog.sirliu.com 最新整理的文章在这里喔:https://blog.sirliu.com/2018/11/shell_lian_xi_ti.html