CentOS安装mysql

查看是否安装过mysql
rpm -qa | grep mysql
 
下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
也可以直接到mysql官网选择其他版本进行下载。
一、解压安装包
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
 
 修改解压后的文件名
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
 
二 安装Mysql
 
1)、创建mysql用户
useradd mysql
 
2)、mysql目录改为mysql读写权限
chown -R mysql:mysql /usr/local/mysql
 
3)初始化数据库
cd mysql
mkdir data
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
这一步会生成一个临时密码,保存着,下面用
 
4)编辑mysql配置文件
vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir =/usr/local/mysql/data
port=3306
max_connections=400
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
federated
# 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]
user=mysql
tmpdir=/tmp
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid
 
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
 
5)测试mysql服务
/usr/local/mysql/support-files/mysql.server start
 
6)创建mysql 软连接
[root@localhost /]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost /]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@localhost /]# service mysql restart
 
7)登录mysql,修改密码(密码为上面生成的临时密码)
 
8)登录mysql数据库 修改密码
mysql -u root -p
Enter password:
SET PASSWORD = PASSWORD('root');
 
9)修改mysql登录用户
use mysql;
 
update user set host='%' where user = 'root';
 
flush privileges;
 
常见问题:
(1)yum -y install numactl
posted @ 2019-11-06 11:46  阿龙阿  阅读(241)  评论(0编辑  收藏  举报