linux-centos7 安装mysql

1.下载mysql,wget安装或者官网下载 地址:https://www.mysql.com/downloads/ 如图:
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

2.tar -zxvf mysql-5.6.41 解压 重命名为mysql,拷贝到/usr/local/目录下,也可自定义位置,但是/etc/my.conf里的basedir 需指定位置为mysql的文件夹路径
3.添加组合用户:groupadd mysql和useradd -r -g mysql mysql
4.进入到mysql目录,分别执行一下命令

cd /usr/local/mysql/
chown -R mysql:mysql ./ 
 ./scripts/mysql_install_db --user=mysql #安装数据库
 chown -R root:root ./
 chown -R mysql:mysql data

5.设置开机自启动

cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql  #设置可执行权限
chkconfig --add mysql 

6.启动mysql

[root@localhost mysql]# service mysql start
Starting MySQL SUCCESS!

启动mysql时可能会报错:
1.

Starting MySQL.181013 06:46:09 mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.

/var/log/mariadb/mariadb.log这个文件不存在或者权限问题

mkdir /var/log/mariadb
touch mariadb.log
chown -R mysql:mysql mariadb.log
[root@localhost bin]# ./mysql -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

软连接指向:

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

3.不能设置密码

mysqld_safe –skip-grant-tables &
 mysqladmin -uroot -p password

错误大多问题因为/etc/my.conf里配置的错误

[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql #mysql安装路径
# 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 -uroot 启动

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.38 sec)

备注:从第2步开始,不执行2之后的步骤也可,设置密码(也不可设置),连接

[root@localhost mysql-5.6.41]# ./bin/mysqladmin -u root password "root"
Warning: Using a password on the command line interface can be insecure.
[root@localhost mysql-5.6.41]# ./bin/mysql -u root -p
Enter password: 

查看

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> use mysql

猜你喜欢

转载自blog.csdn.net/qq_29312259/article/details/83041378