一、查看可以安装的mysql-server
apt-cache search mysql-server
二、安装mysql-server
apt-get install mysql-server
三、配置mysql远程访问
1)登陆mysql
mysql -uroot -p
2)设置账号远程权限
use mysql; update user set Host = "%" where User = "root";
3)修改配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
注释掉
bind-address = 127.0.0.1
四、修改配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
1)在[client]下追加
default-character-set = utf8
2)在[mysqld]下追加
character-set-server = utf8 skip-name-resolve
修改时区
default-time_zone = '+8:00'
修改sql_mode
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
修改最大链接数
max_connections = 3000
3)修改/etc/mysql/conf.d/mysql.cnf
vim /etc/mysql/conf.d/mysql.cnf
在[mysql]下追加
default-character-set = utf8
4)修改root密码(mysql 5.7)
use mysql; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码'; // 或者 update mysql.user set authentication_string=password('新密码') where user='root' and Host = '%';
select user,host,plugin from mysql.user;
如果显示:
+------------------+-----------+-----------------------+ | user | host | plugin | +------------------+-----------+-----------------------+ | root | % | auth_socket | | mysql.session | localhost | mysql_native_password | | mysql.sys | localhost | mysql_native_password | | debian-sys-maint | localhost | mysql_native_password | +------------------+-----------+-----------------------+
需更新认证插件:
update user set plugin="mysql_native_password" where user="root" ;
最后执行:
flush privileges;
五、配置数据库文件分开存放,
1)[mysqld]下增加下面配置
innodb_file_per_table=1
2)删除原数据文件,如有数据,记得提前备份数据库
删除原来的ibdata1文件及日志文件ib_logfile*,删除/var/lib/mysql目录下的应用数据库文件夹(mysql文件夹不要删)
六、检查配置文件是否有问题
mysqld --verbose --help|grep ERROR
七、重启mysql
service mysql restart
八、验证配置信息
1)查询数据库编码方式
show variables like 'character%';
2)查看最大连接数
show variables like '%max_connections%';