MySql教程

mysql安装

本文主要是介绍mysql安装,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.通过编译、二进制安装MySQL5.7

1).上传并解压安装包
[root@Centos7 ~]# cd /data
[root@Centos7 ~]# tar -zxvf mysql-5.7.35-el7-x86_64.tar.gz
2).创建软连接、创建用户
[root@Centos7 ~]# ln -s /data/mysql /usr/local/mysql
[root@Centos7 ~]# cd /data/mysql
[root@Centos7 ~]# mkdir data
[root@Centos7 ~]# groupadd mysql
[root@Centos7 ~]# useradd -M -g mysql -s /sbin/nologin -d /usr/local/mysql mysql
[root@Centos7 ~]# chown -R mysql.mysql /usr/local/mysql/
3).安装库
[root@Centos7 ~]# yum install -y libnuma*
4).mysql初始化、启动、修改密码,设置开机启动
#mysql初始化
[root@Centos7 ~]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@Centos7 ~]# vim /etc/my.conf
[mysqld]
port=3306
character-set-server=utf8
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#innodb_buffer_pool_size=8M
max_connections=1000
slow_query_log = 1
slow_query_log_file=/usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
max_connections=1000
socket=/var/lib/mysql/mysql.sock
[mysqld_safe]
 
log-error=/usr/local/mysql/data/error.log
 
pid-file=/usr/local/mysql/data/mysql.pid
 
tmpdir=/usr/local/mysql/tmp
 
[client]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysql]
default-character-set=utf8
cp ./support-files/mysql.server /etc/init.d/mysqld
 
vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
mysqld_pid_file_path=/usr/local/mysql/data/mysql.pid

#启动数据库
[root@Centos7 ~]# service mysqld start
#修改密码
[root@Centos7 ~]# ./bin/mysql -u root -p
 
SET PASSWORD FOR 'root'@localhost=PASSWORD('Your Password');
 
#添加环境变量
[root@Centos7 ~]# vim /etc/profile
 
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
 
#环境变量生效
[root@Centos7 ~]# source /etc/profile
设置开机自启
[root@Centos7 ~]# chmod +x /etc/rc.d/init.d/mysqld
[root@Centos7 ~]# chkconfig --add mysqld
[root@Centos7 ~]# chkconfig --list mysqld

2.二进制安装mariadb10.4

1).卸载mysql
[root@Centos7 ~]# rpm -ev --nodeps mysql*
2).上传解压安装包
[root@Centos7 ~]# cd /data
[root@Centos7 data]# tar -zxvf mariadb-10.4.11-linux-x86_64.tar.gz -C /usr/local
[root@Centos7 data]# mv /usr/local/mariadb-10.4.11-linux-x86_64 /usr/local/mysql
3).创建安装目录、用户
[root@Centos7 data]# groupadd -r mysql
[root@Centos7 data]# useradd -r -g mysql -s /sbin/nologin -d /usr/local/mariadb -M mysql
[root@Centos7 data]# mkdir -pv /usr/local/mysql/data
[root@Centos7 data]# cd /usr/local/mysql
[root@Centos7 mysql]# chown -R root .
[root@Centos7 mysql]# chown -R mysql data
4).执行安装
#安装库
[root@Centos7 mysql]# yum install libstdc++
[root@Centos7 mysql]# scripts/mysql_install_db --user=mysql
5).启动
[root@Centos7 mysql]# ./bin/mysqld_safe --user=mysql &
6).设置自启
[root@Centos7 mysql]# cp support-files/systemd/mariadb.service /usr/lib/systemd/system/mariadb.service
[root@Centos7 mysql]# systemctl enable mariadb
这篇关于mysql安装的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!