1. 下载5.7的安装包
wget https://dev.mysql.com/get/mysql-5.7.39-el7-x86_64.tar.gz想要其他版本,可以在官方网站下载:
https://dev.mysql.com/downloads/mysql/
2. 解压安装
tar -zxvf mysql-5.7.39-el7-x86_64.tar.gz
改个名看着方便,不改也行
mv mysql-5.7.39-el7-x86_64 mysql
进入mysql文件夹,创建一个必要的文件夹
cd mysql
mkdir log tmp var data conf
conf里面创建cnf文件
vim conf/my.cnf
里面的路径需要自己改下
[mysqld] user = uplus port = 3306 key_buffer_size = 256M max_allowed_packet = 256M slave_max_allowed_packet = 256M table_open_cache = 512 sort_buffer_size = 2M net_buffer_length = 8K read_buffer_size = 2M read_rnd_buffer_size = 512K myisam_sort_buffer_size = 64M thread_cache_size = 64 query_cache_size = 64M max_connections = 32000 tmp_table_size = 128M long_query_time = 3 slow_query_log innodb_buffer_pool_size = 7000M innodb_flush_log_at_trx_commit = 0 innodb_flush_method = O_DIRECT innodb_file_format = barracuda innodb_log_file_size = 1G innodb_log_files_in_group = 3 character_set_server = utf8 log_timestamps = SYSTEM #have_statement_timeout = NO ############### PATH ############## basedir = /home/uplus/package/mysql datadir = /home/uplus/package/mysql/data tmpdir = /home/uplus/package/mysql/tmp socket = /home/uplus/package/mysql/var/mysql.sock pid_file = /home/uplus/package/mysql/var/mysql.pid general_log_file = /home/uplus/package/mysql/log/general.log innodb_data_home_dir = /home/uplus/package/mysql/data slow_query_log_file = /home/uplus/package/mysql/log/slow.log log_error = /home/uplus/package/mysql/log/error.log sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysql] default-character-set = utf8进入mysql/bin 目录,进行安装
./mysqld --initialize --basedir=/home/uplus/package/mysql/ --datadir=/home/uplus/package/mysql/data --user=uplus --socket=/home/uplus/package/mysql/var --port=3306
如果安装报错:
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory。
需要安装两个包:
yum install -y libaio.so.1
yum install -y libaio
初始化完成后,{BANNED}最佳后一行会显示root密码,一定要保存下来。
启动mysql
需要根据实际修改路径
nohup bin/mysqld_safe --defaults-file=/home/uplus/package/mysql/conf/my.cnf --socket=/home/uplus/package/mysql/var/mysql.sock &启动后,必须要对Mysql的root密码就行修改
先登录mysql
bin/mysql -u root -S/home/uplus/package/mysql/var/mysql.sock -p
输入初始的密码
set password=password('123456');
配置远程登陆权限
grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;
查看是否成功
use mysql;
select host,user from user;
退出myql
配置环境变量和开机启动
ln -s /home/hadoop/mysql/var/mysql.sock /tmp/mysql.sock
设置环境变量
export MYSQL_HOME=/home/uplus/package/mysql
export PATH=$MYSQL_HOME/bin:$PATH
如果有root权限 可以设置开机启动
cp support-files/mysql.server /etc/init.d/mysql
停止Mysql服务的方法:
mysqladmin -uroot -p shutdown -S /home/uplus/package/var/mysql.sock