Linux安装mysql

以下安装过程亲测成功,只要按照命令复制就可以。

1.上传安装包

mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz压缩包下载

将下载的mysql压缩包上传到Linux系统的usr/local目录下面。

2.安装mysql

进入到usr/local目录下面解压mysql压缩包

cd /usr/local

tar -zxvf  mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz

将解压的文件改名

mv mysql-5.6.41-linux-glibc2.12-x86_64 mysql

安装一些必要的库

yum -y install numactl

yum install libaio* -y

添加系统mysql组和mysql用户:

groupadd mysql
useradd -r -g mysql mysql

进入到mysql里面:

cd /usr/local/mysql

修改当前目录拥有者为mysql用户:

chown -R mysql:mysql ./

安装数据库:

./scripts/mysql_install_db --user=mysql 

修改当前data目录拥有者为mysql用户:执行命令 

chown -R mysql:mysql data

添加开机启动:执行命令

cp support-files/mysql.server /etc/init.d/mysql

修改mysql配置

vim /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/mysql.log
pid-file=/usr/local/mysql/mysql.pid

启动mysql服务:执行命令

service mysql start

修改mysql的root用户密码:

./bin/mysqladmin -u root password '密码'

ln -s /usr/local/mysql/bin/mysql /usr/bin (添加链接)

进入mysql后查询账号密码

select user,host from mysql.user;

Linux安装mysql_第1张图片

将匿名用户删除,一定要删除不然有时候会匿名登陆没有数据

delete from mysql.user where user=" ";

mysql到此就安装完了。 如遇到错误

1.Starting MySQL.180925 14:59:38 mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

是因为在centos7系统,执行以下命令

mkdir /var/log/mariadb  
touch /var/log/mariadb/mariadb.log  
chown -R mysql:mysql  /var/log/mariadb/

 

你可能感兴趣的:(Linux安装mysql)