前言:
现在同学们对“linux怎么启动mysql”大致比较看重,看官们都需要知道一些“linux怎么启动mysql”的相关内容。那么小编在网络上网罗了一些有关“linux怎么启动mysql””的相关知识,希望我们能喜欢,我们一起来学习一下吧!1.系统优化:
关闭selinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
安装依赖包
yum -y install libevent
sysctl.conf 优化:
cat >> /etc/sysctl.conf << EOF
fs.aio-max-nr = 1048576
fs.file-max = 681574400
kernel.shmmax = 137438953472
kernel.shmmni = 4096
kernel.sem = 250 32000 100 200
net.ipv4.ip_local_port_range = 9000 65000
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
EOF
sysctl -p
limit 优化:
cat >> /etc/security/limits.conf << EOF
* soft nproc 65536
* hard nproc 65536
* soft nofile 65536
* hard nofile 65536
EOF
cat >> /etc/security/limits.d/20-nproc.conf << EOF
* soft nproc unlimited
* hard nproc unlimited
EOF
cat >> /etc/pam.d/login << EOF
session required /lib/security/pam_limits.so
session required pam_limits.so
EOF
cat >> /etc/profile << EOF
ulimit -HSn 65535
EOF
source /etc/profile
2.在安装前需要确定现在这个系统有没有 mysql,如果有那么必须卸载。
(1)查看mysql数据库
rpm -qa | grep -i mysql
(2)卸载mysql数据库
rpm -e --nodeps mysql 文件名
(3)查找mysql文件
find / -name mysql
(4)删除mysql有锁文件和配置文件my.cnf(自己上传的别错删了)
rm -rf 指定路径下的文件名
3.解压缩mysql文件
(1)xz –d /usr/local/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
(2)tar –xvf /usr/local/mysql-8.0.16-linux-glibc2.12-x86_64.tar
(3)mv /usr/local/mysql-8.0.16-linux-glibc2.12-x86_64 /usr/local/mysql
4.进入操作系统,建立用户和安装目录
mkdir -p /opt/mysql/tmp
mkdir -p /opt/mysql/dumps
mkdir -p /opt/mysql/log
mkdir -p /opt/mysql/data
mkdir -p /opt/mysql/undo
mkdir -p /opt/servers/mysql
touch /opt/mysql/log/error.log
5.进入数据库软件目录,解压安装包,设置环境变量
cp -R ./* /opt/servers/mysql
cd /opt/servers/mysql
复制数据库启动文件去操作系统启动文件夹下,并且设置临时环境变量和改变安装目录权限
ln -s /opt/servers/mysql /usr/local/mysql
export PATH=$PATH:/usr/local/mysql/bin
创建用户mysql
groupadd -g 512 mysql
useradd -g 512 -d /opt mysql
chown -R mysql:mysql /opt
chmod -R 755 /opt
设置永久环境变量,编辑vi /etc/profile文件,在最后一行加入
export PATH=$PATH:/usr/local/mysql/bin
6.安装mysql服务
进入安装目录
cd /opt/servers/mysql/bin
mysql初始化配置
1.切换到mysql用户权限
su mysql
配置mysql参数文件my.cnf,便捷my.cnf 8G配置参数文件如下:
[mysql]
# 设置mysql客户端默认字符集
#default-character-set=utf8
[client]
port=3306
socket=/opt/mysql/tmp/mysql.sock
[mysqldump]
quick
max_allowed_packet=64M
[mysqld_safe]
log-error=/opt/mysql/log/error.log
pid-file=/opt/mysql/mysqld.pid
[mysql]
no-auto-rehash
[mysqld]
server_id=1
user=mysql
port=3306
mysqlx_port=33060
mysqlx_socket=/opt/mysql/tmp/mysqlx.sock
socket=/opt/mysql/tmp/mysql.sock
basedir=/opt/servers/mysql
datadir=/opt/mysql/data
lower_case_table_names=1
character_set_server=utf8
collation_server=utf8_unicode_ci
innodb_undo_directory=/opt/mysql/undo
innodb_undo_tablespaces=4
innodb_data_file_path=ibdata1:512M:autoextend
innodb_page_size=16k
default_authentication_plugin=mysql_native_password
open_files_limit=10240
back_log=600
max_connections=3000
max_connect_errors=6000
table_open_cache=1000
max_allowed_packet=64M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=300
thread_stack=256K
transaction_isolation=READ-COMMITTED
tmp_table_size=256M
max_heap_table_size=256M
long_query_time=2
log_bin=/opt/mysql/tmp/mysql-bin
binlog_cache_size=4M
max_binlog_cache_size=8M
max_binlog_size=1G
binlog_expire_logs_seconds=2592000
key_buffer_size=2048M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=64M
skip_name_resolve
innodb_buffer_pool_size=6144M
innodb_thread_concurrency=8
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=16M
innodb_log_file_size=128M
innodb_log_files_in_group=3
innodb_max_dirty_pages_pct=90
innodb_lock_wait_timeout=120
innodb_file_per_table=1
初始化生成data目录(切记不要手动创建data目录)(补充:mysql用户下初始化不成功(没有生成密码),用root用户来操作,最后记得把生成data目录赋予mysql用户)
/usr/local/mysql/bin/mysqld --initialize
如果当前所在目录为bin录下,命令形式为./mysqld --initialize
./不能省略,否则出错,因为省略后系统会当成mysqld程序执行,而不是bin目录下的mysqld可执行文件
安装mysql数据库服务
./mysqld --initialize-insecure --user=mysql --basedir=/opt/servers/mysql/ --datadir==/opt/mysql/data --innodb_undo_directory=/opt/mysql/undo --innodb_undo_tablespaces=4 --socket=/opt/mysql/tmp/mysql.socket --port=3306 --innodb_data_file_path=ibdata1=512M:autoextend --lower-case-table-names=1
7.软连接与开机启动项设置
1.ln -s /usr/local/mysql/bin/mysql /usr/bin
2.mysqld配置,拷贝启动文件到/etc/init.d/目录下并重命令为mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
3.检查自启动项列表中有没有mysqld
chkconfig --list mysqld
4.如果没有就添加mysqld
chkconfig --add mysqld
5.设置开机启动
chkconfig mysqld on
6.启动测试
service mysqld start
8.如果启动过程中遇到pid问题解决办法
1.如果无法启动,且提示pid错误;首先一定要确认配置文件有没有打错字母,改正后,删除data目录
rm -rf /opt/mysql/data
2.重新初始化一遍
/usr/local/mysql/bin/mysqld --initialize
3.记下密码后,追加755权限给data目录
chmod 755 /opt/mysql/data
4.再重新启动mysql服务
service mysqld start
标签: #linux怎么启动mysql