linux centos 安装 mysql 并设置开机启动:
1.下载mysql
社区版GPL下载地址:https://dev.mysql.com/downloads/mysql/
选择-Select Operating System:Linux-Generic
选择-Select OS Version:All
选择下载:Linux - Generic (glibc 2.12) (x86, 64-bit), TAR(mysql-8.0.12-linux-glibc2.12-x86_64.tar)
2.上传并解压mysql
# tar -xvf mysql-8.0.12-linux-glibc2.12-x86_64.tar # tar xvJf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz
3.创建data文件
cd /usr/local/app/mysql/mysql-8.0.12-linux-glibc2.12-x86_64 mkdir data
4.创建配置文件
cd /etc/ touch my.cnf vi my.cnf
输入内容
[client] port = 3306 socket = /tmp/mysql.sock [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8' basedir=/usr/local/app/mysql/mysql-8.0.12-linux-glibc2.12-x86_64 datadir=/usr/local/app/mysql/mysql-8.0.12-linux-glibc2.12-x86_64/data socket=/tmp/mysql.sock log-error=/var/log/mysqld.log
5.创建mysql组和用户
$ groupadd mysql $ useradd -g mysql mysql
6.初始化mysql
/usr/local/app/mysql/mysql-8.0.12-linux-glibc2.12-x86_64/bin/mysqld --initialize --user=mysql --basedir=/usr/local/app/mysql/mysql-8.0.12-linux-glibc2.12-x86_64/ --datadir=/usr/local/app/mysql/mysql-8.0.12-linux-glibc2.12-x86_64/data/
7.启动mysql
# cd /usr/local/app/mysql/mysql-8.0.12-linux-glibc2.12-x86_64/support-files # ./mysql.server start Starting MySQL.. SUCCESS!
8.查看初始密码
# cat /var/log/mysqld.log
找到 A temporary password is generated for root@localhost: j-;M>Qlef39D。root@localhost:后面就是你的初始密码。
9.本地连接mysql
# cd /usr/local/app/mysql/mysql-8.0.12-linux-glibc2.12-x86_64/bin # ./mysql -hlocalhost -uroot -p
需要你输入上面查到的密码。
10.新建用户并设置可以远程连接
修改root密码
> alter user user() identified by "123456";
创建用户
> create user 'itxw'@'%' identified with mysql_native_password by '123456';
授予权限
> grant all privileges on *.* to 'itxw'@'%';
刷新
> flush privileges;
防火墙开放mysql端口
# firewall-cmd --zone=public --add-port=3306/tcp --permanent # firewall-cmd --reload
12.设置mysql开机启动
# cd /usr/local/app/mysql/mysql-8.0.12-linux-glibc2.12-x86_64/support-files # cp mysql.server /etc/init.d/mysqld # chkconfig --add mysqld
启动mysql服务
# service mysqld start
停止mysql服务
# service mysqld stop
重启mysql服务
# service mysqld restart