linux服务器安装配置mysql
目的:服务器安装配置mysql实施记录,下次有需要备查。
1.创建mysql用户
useradd mysql
passwd mysql #这里输入密码,注意记录密码
2.解压缩下载的mysql包
mkdir /opt/mysql
tar -zxvf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz -C /opt/mysql
cd /opt/mysql
mv mysql-5.6.41-linux-glibc2.12-x86_64/* .
rm -rf mysql-5.6.41-linux-glibc2.12-x86_64/
yum -y install perl perl-devel gcc kernel-devel autoconf
3.将mysql目录的权限授给mysql用户和mysql组
chown -R mysql:mysql /opt/mysql/
4.切换到mysql用户,执行安装
su - mysql
cd /opt/mysql
/opt/mysql/scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
注意,如果安装报错:
scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory
需要切换到root用户,安装perl以及perl-devel,执行下面命令:
yum -y install perl perl-devel
)
5.创建错误日志
touch mysql_error.log
6.复制并修改配置文件,添加mysql服务
切换到root用户
复制文件:
su - root
cd /opt/mysql/support-files
cp my-default.cnf /etc/my.cnf
cat /dev/null > /etc/my.cnf
vi /etc/my.cnf
#全部删除,改为如下:
[mysqld]
# port=33060
basedir = /opt/mysql
datadir = /opt/mysql/data
socket = /tmp/mysql.sock
log-error=/opt/mysql/mysql_error.log
skip-name-resolve
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
#init_connect='set names utf8'
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names = 1
max_allowed_packet = 32M
table_open_cache = 1024
sort_buffer_size = 4M
join_buffer_size = 2M
net_buffer_length = 8M
read_buffer_size = 4M
read_rnd_buffer_size = 8M
thread_cache_size = 300
query_cache_size = 1024M
query_cache_limit = 2M
thread_concurrency = 8
wait_timeout = 315360000
max_connections = 300
max_connect_errors=1844674407370954751
max_connect_errors = 10000
#event_scheduler=1
#innodb_log_file_size=256M
innodb_buffer_pool_size = 4094M
innodb_additional_mem_pool_size = 32M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
innodb_thread_concurrency=8
#innodb_sort_buffer_size=32M
innodb_open_files=4096
innodb_write_io_threads=2
innodb_read_io_threads=2
innodb_max_dirty_pages_pct = 90
innodb_file_per_table=1
[client]
socket=/tmp/mysql.sock
default-character-set=utf8
#结束
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql
#修改文件中的两个变更值
basedir=/opt/mysql/
datadir=/opt/mysql/data/
7.配置mysql的环境变量
vi /etc/profile
#添加如下内容:
export PATH=$PATH:/opt/mysql/bin
source /etc/profile
8.启用mysql
chkconfig --add mysql
chkconfig mysql on
service mysql start
Starting MySQL… SUCCESS!
9.设置mysql的root用户密码
/opt/mysql/bin/mysqladmin -u root password 'yourpasswd'
# 这里输入密码,注意记录密码
# mysql root用户登录
mysql -uroot -pyourpasswd
注意这里的数据库root用户密码不要和linux用户mysql的密码混淆了
10.给root用户配置远程访问权限
设置后可通过客户端连接
#>sql
GRANT ALL PRIVILEGES on *.* to 'root'@'%' identified by 'yourpasswd';
flush privileges;