Mysql Linux单机安装与配置
下载安装包
到官网https://dev.mysql.com/downloads/mysql/ 下载对应的安装包。这里我们选择安装mysql-8.0.27的二进制包。
cd /tmp
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
tar xvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.27-linux-glibc2.12-x86_64/* /home/mysql
配置Mysql
#添加mysql用户与组
groupadd mysql
useradd -r -g mysql mysql
passwd mysql #修改mysql用户密码
chown -R mysql:mysql /home/mysql
usermod -d /home/mysql mysql
chmod 644 /etc/my.cnf
配置mysql配置文件
#添加/etc/my.cnf文件
[mysql]
default-character-set=utf8mb4
[mysqld]
#忽略大小写
server_id=1
lower_case_table_names=1
skip-name-resolve
port=3306
#mysql安装目录
basedir=/home/mysql/
#mysql数据库数据存放目录
datadir=/home/mysql/data
log_bin=mysql-bin
gtid-mode=on
enforce-gtid-consistency=true
log_error=/home/mysql/logs/mysql_err.log
#允许最大连接数
max_connections=200
character-set-server=utf8mb4
default-storage-engine=INNODB
mysql启动与停止
初始化mysql,记住控制台打印的初始化的密码
./bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --initialize
启动mysql
/home/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql
./bin/mysqladmin -uroot -pca2804 shutdown
修改默认用户密码
mysql -uroot -p #输入之前获取的密码登录mysql
alter user 'root'@'localhost' IDENTIFIED with mysql_native_password by '123456'
vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://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=/home/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
配置用户远程登录
update user set user.Host='%' where user.User='root';
grant all privileges on *.* to 'root'@'%';
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
编程之家!
喜欢就支持一下吧