Mysql安装步骤:
1.拷贝
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 到服务器的/opt/software
2.解压缩
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.22-linux-glibc2.12-x86_64 /opt/server/mysql-5.7.22
创建数据存储文件夹
mkdir data
3.查看support-files有没有my_default.cnf文件,没有则创建并拷贝到/etc/my.cnf
cp /opt/server/mysql-5.7.22/support-files/my_default.cnf /etc/my.cnf
# For advice on how to change settings please see
# *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES #非严格模式
# 一般配置选项
basedir = /opt/server/mysql-5.7.22
datadir = /opt/server/mysql-5.7.22/data
port = 3306
socket = /opt/server/mysql-5.7.22/mysqld.sock
character-set-server=utf8 #默认字符集
lower_case_table_names=1 #不区分大小写
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=mysql-bin
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
4.初始化数据库
mysqld –initialize –user=mysql –basedir=/opt/server/mysql-5.7.22 –datadir=/opt/server//mysql-5.7.22/data
下面的是root用户生成的密码:
5.启动mysql
./bin/mysqld_safe
./bin/mysql -u root -p
用初始化的密码登录:
修改密码
alter user ‘root’@’localhost’ identified by ‘root’;
6.添加远程访问权限
在本机先使用root用户登录mysql: mysql -u root -p"youpassword" 进行授权操作:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
重载授权表
退出mysql数据库:
exit;
然后用新密码重新登录
常见问题:
1.大小写不区分:
lower_case_table_names=1 #不区分大小写
这个的位置放在上面
2.ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
建立软连接 anzhaung