在深度Linux中安装MySQL5.7.22 (踩了比较多的坑)

在Linux(debian)中安装MySQL5.7.22 (踩了比较多的坑)

1、下载tar包

mkdir -p /usr/software
cd /usr/software
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

2、将mysql安装到/usr/local/mysql下

解压
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
移动
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/
重命名
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql

3、新建data目录

mkdir -p /usr/local/mysql/data

4、新建mysql用户、mysql用户组

mysql用户组
groupadd mysql
mysql用户
useradd mysql -g mysql

5、将/usr/local/mysql的所有者及所属组改为mysql

chown -R mysql.mysql /usr/local/mysql

6、初始化mysql

cd /usr/local/mysql/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
记住生成的临时密码
如果忘记密码或者想重新初始化,可以先将mysql/data目录中文件删除,然后再执行初始化命令

7、配置my.cnf

vi /etc/my.cnf

精简版:只要这两行 其余的注释掉
[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/

可选版:
#For advice on how to change settings please see
#http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
#*** 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 = /usr/local/mysql/
datadir = /usr/local/mysql/data
port = 3306
character-set-server = utf8
explicit_defaults_for_timestamp = true
#socket = /var/run/mysqld/mysqld.sock

#下面是可选项,要不要都行,如果出现启动错误,则全部注释掉,保留最基本的配置选项,然后尝试添加某些配置项后启动,检测配置项是否有误
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

[client]
/bin/bash: Q: command not found

8、启动

cd /usr/local/mysql/bin
启动:./mysqld_safe --user=mysql &

9、设为开机启动

cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql
将mysql目录填上:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
授权:chmod +x /etc/init.d/mysql
设为开机启动:chkconfig --add mysql

10、service启动

重启服务:service mysql restart
停止服务:service mysql stop
启动服务:service mysql start
查看服务:service mysql status

11、登录mysql修改密码授权远程登录

cd /usr/local/mysql/bin
登录:./mysql -u root -p 输入临时密码
出现了这个错误
./mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
解决方案:
找到文件位置
find / -name libncurses.so.5
设置共享路径
ln -s /lib/i386-linux-gnu/libncurses.so.5 /usr/lib/libncurses.so.5
然后还是报错
./mysql: error while loading shared libraries: libncurses.so.5: wrong ELF class: ELFCLASS32
64位软件读取了32位的库
apt-get install lib64ncurses5
ln -s /lib64/libncurses.so.5 /usr/lib/libncurses.so.5

修改密码:set password for root@localhost = password(‘root’);
登录授权:grant all privileges on . to ‘root’@’%’ identified by ‘root’ with grant option;
授权生效:flush privileges;
可使用navicat进行登录,注意关闭防火墙或开放3306端口

你可能感兴趣的:(Linux,MySQL)