linux安装mysql数据库

1.软件环境

1.服务器:centos 6.5

2.数据库版本:mysql-5.7.20

2.安装前检查系统

1.检查系统是否包含libaio 包

yum search libaio // 查询
yum install libaio // 安装

2.检查系统是否安装mariadb数据库,centos系统默认安装的数据库,会在/etc目录下生成my.cnf文件,该文件可能会导致安装mysql发生异常,所以建议直接将mariadb卸载

rpm -qa | grep mari* // 查询是否安装了maridb
rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps  // 忽略依赖卸载软件

3.安装mysql

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar zxvf /path/to/mysql-VERSION-OS.tar.gz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
#此步执行完毕后,会将临时密码打印在控制台上,可以用此密码进入mysql
bin/mysqld --initialize --user=mysql 
bin/mysql_ssl_rsa_setup              
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysqld
#开机启动
chkconfig mysqld on

4.配置数据库

1.将mysqld加入环境变量中

vim /etc/profile
#在最后加上
export PATH=$PATH:YOUR MYSQL PATH/bin

2.修改密码

alter user user() identified by "password";
flush privileges;
exit;

3.修改mysql配置文件,在etc目录下创建my.cnf文件

touch /etc/my.cnf
vim /etc/my.cnf
#写入如下内容

[mysqld]
basedir = 你的mysql路径
datadir = 你的mysql数据文件路径
port=3306
server-id = 1
character-set-server = utf8
general_log = 1
skip-name-resolve
back_log = 300

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128 
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 28M
key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30


performance_schema = 0
explicit_defaults_for_timestamp

#lower_case_table_names = 1



myisam_sort_buffer_size = 8M
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES 

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

[client]
#socket =/data/db/mysql-5.7.12/mysql.sock

4.重启数据库

service mysqld restart

5.授权远程访问

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION 

你可能感兴趣的:(linux安装mysql数据库)