1.安装MySQL
在 Ubuntu 18.04 中,默认情况下,只有最新版本的 MySQL 包含在 APT 软件包存储库中,要安装它,只需更新服务器上的包索引并安装默认包 apt-get。
#命令1
sudo apt-get update
#命令2
sudo apt-get install mysql-server
2.配置MySQL
2.1 安装配置
sudo mysql_secure_installation
配置项较多,如下所示:
#1 VALIDATE PASSWORD PLUGIN can be used to test passwords... Press y|Y for Yes, any other key for No: N (我的选项) #2 Please set the password for root here... New password: (输入密码) Re-enter new password: (重复输入) #3 By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them... Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项) #4 Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network... Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项) #5 By default, MySQL comes with a database named 'test' that anyone can access... Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项) #6 Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)
2.2 检查mysql服务状态:
systemctl status mysql.service
3 配置连接
如果想从其他电脑连接过来,请注意2点
(1)如果mysql监听是127.0.0.1:3306 请修改配置文件/etc/mysql/my.cnf
bind-address=127.0.0.1 修改为 bind-address=0.0.0.0
(2)授权连接
登录 mysql -uroot -p (输入密码)
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY "123456";
4. 忘记密码修改
配置文件[mysqld]下加入skip-grant-tables
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
重启mysql,执行mysql(无需密码登录)
use mysql
改密码:update user set password=password("root") where user="root";
mysql5.7以上版本--> UPDATE user SET authentication_string=PASSWORD("root") WHERE user="root";
flush
privileges
;
exit
5. 卸载
sudo apt-get autoremove --purge mysql-server-5.7
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt-get remove mysql-server (可能没有) sudo apt-get autoremove mysql-server (可能没有) sudo apt-get remove mysql-common
清理残留数据
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
sudo apt autoremove sudo apt autoreclean
转载请注明:梦绘设计 » 数据库 » Ubuntu 18.04安装mysql
版权声明
本站《作品展示》类文章均为原创,转载必须注明出处,技术分享类文章部分来源于网络,版权归原作者所有,若侵权请留言。