linux下安装mysql
mysql下载链接
https://dev.mysql.com/downloads/mysql/
本次演示版本为 mysql-5.7.28 如下图所示
将下载的压缩包上传至linux虚拟机内
解压当前亚索包 至 、/usr/local/下
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
将名称改为mysql
mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql
创建数据目录
cd mysql mkdir data
创建用户组
groupadd mysql useradd -r -g mysql mysql
赋予权限
chown mysql:mysql -R /usr/local/mysql
修改mysql配置文件
vim /etc/my.cnf
修改去下
[mysqld] bind-address=0.0.0.0 user=mysql port=3306 basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
进去mysql的bin目录下
cd /usr/local/mysql/bin
初始化mysql
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql --initialize
复制下初始密码
将mysql.server放置到/etc/init.d/mysql目录下
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动mysql
service mysql start
解决上述报错
mkdir /var/log/mariadb touch /var/log/mariadb/mariadb.log chown -R mysql /var/log/mariadb/
重启mysql
service mysql restart
解决无文件夹的问题 并赋予权限重启mysql
mkdir mysql chown -R mysql /var/lib/mysql/ service mysql restart
启动成功 登录mysql
./mysql -u root -p
set password=password('XXXX');#设置自己的密码 grant all privileges on *.* to 'root'@'%' identified by 'root'; #赋予远程访问权限 flush privileges;#刷新权限
一个简单的mysql创建已经成功了,如有问题欢迎交流!